pim-import 3.1.1 → 3.1.4

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.
@@ -271,6 +271,13 @@ export const importFamilies = async (
271
271
 
272
272
  await createOrUpdatePage(topicFamily);
273
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
+
274
281
  if (limit !== -1 && count + 1 - offset >= limit) {
275
282
  break;
276
283
  }
@@ -282,18 +289,16 @@ export const importFamilies = async (
282
289
  serverUtils.log(family.data.code);
283
290
  }
284
291
  }
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);
290
- }
291
292
  }
292
293
  count++;
293
294
  }
294
295
 
295
296
  const nextOffset = Number(offset) + Number(limit);
296
297
 
298
+ if (serverUtils) {
299
+ serverUtils.updateProgress(100);
300
+ }
301
+
297
302
  return {
298
303
  offset: nextOffset,
299
304
  limit: Number(limit),
@@ -1224,7 +1224,10 @@ export const importProduct = async (
1224
1224
  return false;
1225
1225
  }
1226
1226
 
1227
- if (productDetails.visibleToWeb === true) {
1227
+ if (
1228
+ productDetails.visibleToWeb === true ||
1229
+ productDetails.code === "0000000-TEST"
1230
+ ) {
1228
1231
  await addProduct(productDetails);
1229
1232
  return true;
1230
1233
  } else {
@@ -1442,6 +1445,10 @@ export const setProductsRelationships = async (
1442
1445
  const seconds = secondBetweenTwoDate(timeStart, timeEnd);
1443
1446
  log(`Request time: ${seconds} seconds`);
1444
1447
 
1448
+ if (serverUtils) {
1449
+ serverUtils.updateProgress(100);
1450
+ }
1451
+
1445
1452
  return {
1446
1453
  offset: Number(offset) + Number(limit),
1447
1454
  limit: Number(limit),
@@ -1539,6 +1546,11 @@ export const audit = async (
1539
1546
  await saveJsonToS3(allAudit, filename, path);
1540
1547
  const s3Path = `${path}/${filename}`;
1541
1548
 
1549
+ if (serverUtils) {
1550
+ serverUtils.log(`Saved s3FilePath: ${s3FilePath}`);
1551
+ serverUtils.updateProgress(100);
1552
+ }
1553
+
1542
1554
  return {
1543
1555
  offset: Number(offset),
1544
1556
  limit: Number(limit),
@@ -1589,6 +1601,11 @@ export const audit = async (
1589
1601
  const secs = secondBetweenTwoDate(timeStart, tEnd);
1590
1602
  log(`Execution time: ${secs} seconds`);
1591
1603
 
1604
+ if (serverUtils) {
1605
+ serverUtils.log(`Audit completed`);
1606
+ serverUtils.updateProgress(100);
1607
+ }
1608
+
1592
1609
  return {
1593
1610
  offset: nextOffset,
1594
1611
  limit: limit,
@@ -1626,13 +1643,18 @@ export const audit = async (
1626
1643
  );
1627
1644
 
1628
1645
  if (!productEntry) {
1646
+ let logMessage = "";
1629
1647
  if (catalog) {
1630
- log(
1631
- `The ${audit.product} product was not found in the CMS with catalog ${catalog}`,
1632
- "WARN"
1633
- );
1648
+ logMessage = `The ${audit.product} product was not found in the CMS with catalog ${catalog}`;
1634
1649
  } else {
1635
- log(`The ${audit.product} product was not found in the CMS`, "WARN");
1650
+ logMessage = `The ${audit.product} product was not found in the CMS`;
1651
+ }
1652
+ log(logMessage, "WARN");
1653
+
1654
+ if (serverUtils) {
1655
+ serverUtils.log(logMessage);
1656
+ const progress = Math.floor((++current / allAudit.length) * 100);
1657
+ serverUtils.updateProgress(progress);
1636
1658
  }
1637
1659
  continue;
1638
1660
  }
@@ -1796,6 +1818,10 @@ export const audit = async (
1796
1818
  };
1797
1819
  } else {
1798
1820
  log(`Execution completed`);
1821
+ if (serverUtils) {
1822
+ serverUtils.log(`Execution completed`);
1823
+ serverUtils.updateProgress(100);
1824
+ }
1799
1825
  }
1800
1826
  const tEnd = new Date();
1801
1827
  const secs = secondBetweenTwoDate(timeStart, tEnd);
@@ -1910,33 +1936,41 @@ export const generateTechSpecPdf = async (topicProductId: string) => {
1910
1936
  }
1911
1937
 
1912
1938
  const pdf = await generatePDFByUrl(layoutUrl, "", contents);
1913
- if (serverUtils) {
1914
- serverUtils.updateProgress(45);
1915
- }
1916
- const s3Url = await savePDFToS3(pdf, fileName, "tech-spec");
1917
- if (serverUtils) {
1918
- serverUtils.updateProgress(75);
1919
- }
1939
+ if (pdf) {
1940
+ if (serverUtils) {
1941
+ serverUtils.updateProgress(45);
1942
+ }
1943
+ const s3Url = await savePDFToS3(pdf, fileName, "tech-spec");
1944
+ if (serverUtils) {
1945
+ serverUtils.updateProgress(75);
1946
+ }
1920
1947
 
1921
- log(`Update techSpec field...`);
1922
- topicProduct.fields = await addFieldValue(topicProduct, "techSpec", s3Url);
1948
+ log(`Update techSpec field...`);
1949
+ topicProduct.fields = await addFieldValue(topicProduct, "techSpec", s3Url);
1923
1950
 
1924
- topicProduct = await topicProduct.update();
1925
- if (topicProduct.isPublished()) {
1926
- try {
1927
- topicProduct = await topicProduct.publish();
1928
- } catch (err) {
1929
- log(`Cannot publish entry.`);
1930
- log(err);
1951
+ topicProduct = await topicProduct.update();
1952
+ if (topicProduct.isPublished()) {
1953
+ try {
1954
+ topicProduct = await topicProduct.publish();
1955
+ } catch (err) {
1956
+ log(`Cannot publish entry.`);
1957
+ log(err);
1958
+ }
1931
1959
  }
1932
- }
1933
1960
 
1934
- log(`${topicProductId} techSpec field updated!`);
1935
- if (serverUtils) {
1936
- serverUtils.updateProgress(100);
1937
- }
1961
+ if (serverUtils) {
1962
+ serverUtils.updateProgress(100);
1963
+ }
1938
1964
 
1939
- return s3Url;
1965
+ log(`${topicProductId} techSpec field updated!`);
1966
+ return s3Url;
1967
+ } else {
1968
+ log(
1969
+ `TechSpec PDF generation failed for product: ${topicProductId}!`,
1970
+ "ERROR"
1971
+ );
1972
+ return "";
1973
+ }
1940
1974
  };
1941
1975
 
1942
1976
  const getLightModuleAutoDescriptionByProductFields = async (
@@ -535,6 +535,10 @@ export const importSubFamilies = async (
535
535
 
536
536
  const nextOffset = Number(offset) + Number(limit);
537
537
 
538
+ if (serverUtils) {
539
+ serverUtils.updateProgress(100);
540
+ }
541
+
538
542
  return {
539
543
  offset: nextOffset,
540
544
  limit: Number(limit),
@@ -11,7 +11,6 @@ export { importFamilies } from "./pim/methods/families";
11
11
  export { importProductByCode, setProductsRelationships, setProductRelationships, getAllProductEntriesByCatalog, audit, generateTechSpecPdf, setProductsAutodescription, getProductAutodescription, setProductAutodescriptionByTopicId, removeProductFromColorVariantsByProductLine, removeAllProductModelProductRelations, } from "./pim/methods/products";
12
12
  export { resetIndexSettings } from "./algolia/config";
13
13
  export { reindexFamilies, reindexFamily, removeFamilyObject, } from "./algolia/families";
14
- export { pipedreamReindex } from "./algolia/pipedreamReindex";
15
14
  export { reindexSubFamilies, reindexSubFamily, removeSubFamilyObject, } from "./algolia/subFamilies";
16
15
  export { reindexProduct, reindexProducts, removeProductObject, } from "./algolia/products";
17
16
  export { reindexSubModel, reindexSubModels, removeSubModelObject, } from "./algolia/subModels";
package/types/index.d.ts CHANGED
@@ -11,7 +11,6 @@ export { importFamilies } from "./pim/methods/families";
11
11
  export { importProductByCode, setProductsRelationships, setProductRelationships, getAllProductEntriesByCatalog, audit, generateTechSpecPdf, setProductsAutodescription, getProductAutodescription, setProductAutodescriptionByTopicId, removeProductFromColorVariantsByProductLine, removeAllProductModelProductRelations, } from "./pim/methods/products";
12
12
  export { resetIndexSettings } from "./algolia/config";
13
13
  export { reindexFamilies, reindexFamily, removeFamilyObject, } from "./algolia/families";
14
- export { pipedreamReindex } from "./algolia/pipedreamReindex";
15
14
  export { reindexSubFamilies, reindexSubFamily, removeSubFamilyObject, } from "./algolia/subFamilies";
16
15
  export { reindexProduct, reindexProducts, removeProductObject, } from "./algolia/products";
17
16
  export { reindexSubModel, reindexSubModels, removeSubModelObject, } from "./algolia/subModels";
@@ -7,5 +7,5 @@ interface PDFHeaderAndFooter {
7
7
  header?: Columns;
8
8
  footer?: Columns;
9
9
  }
10
- export declare const generatePDFByUrl: (url: string, path?: string, contents?: PDFHeaderAndFooter | undefined) => Promise<Buffer>;
10
+ export declare const generatePDFByUrl: (url: string, path?: string, contents?: PDFHeaderAndFooter | undefined) => Promise<"" | Buffer>;
11
11
  export {};
@@ -1,22 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.pipedreamReindex = void 0;
7
- const logs_1 = require("../libs/logs");
8
- const axios_1 = __importDefault(require("@atoms-studio/axios"));
9
- const pipedreamReindex = async (reindexType, catalogCode) => {
10
- logs_1.log(`pipedreamReindex - reindexType: ${reindexType} catalogCode: ${catalogCode}`);
11
- if (!process?.env?.FPI_PIPEDREAM_ALGOLIA) {
12
- logs_1.log(`FPI PIPEDREAM ALGOLIA environment variable not found, reindex algolia from Pipedream cannot be started!`, "WARN");
13
- return;
14
- }
15
- axios_1.default.post(process.env.FPI_PIPEDREAM_ALGOLIA, {
16
- isReindexByImport: true,
17
- reindexType,
18
- catalogCode,
19
- });
20
- };
21
- exports.pipedreamReindex = pipedreamReindex;
22
- //# sourceMappingURL=pipedreamReindex.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"pipedreamReindex.js","sourceRoot":"","sources":["../../src/algolia/pipedreamReindex.ts"],"names":[],"mappings":";;;;;;AACA,uCAAmC;AACnC,gEAAwC;AAIjC,MAAM,gBAAgB,GAAG,KAAK,EACnC,WAAkC,EAClC,WAA8B,EACf,EAAE;IACjB,UAAG,CACD,mCAAmC,WAAW,iBAAiB,WAAW,EAAE,CAC7E,CAAC;IAEF,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,qBAAqB,EAAE;QACxC,UAAG,CACD,yGAAyG,EACzG,MAAM,CACP,CAAC;QACF,OAAO;KACR;IAED,eAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE;QAC5C,iBAAiB,EAAE,IAAI;QACvB,WAAW;QACX,WAAW;KACZ,CAAC,CAAC;AACL,CAAC,CAAC;AArBW,QAAA,gBAAgB,oBAqB3B"}
@@ -1,28 +0,0 @@
1
- import { AvailableCatalogs } from "src/types";
2
- import { log } from "../libs/logs";
3
- import axios from "@atoms-studio/axios";
4
-
5
- type AvailablreReindexType = "reindexFamilies" | "reindexSubFamilies";
6
-
7
- export const pipedreamReindex = async (
8
- reindexType: AvailablreReindexType,
9
- catalogCode: AvailableCatalogs
10
- ): Promise<void> => {
11
- log(
12
- `pipedreamReindex - reindexType: ${reindexType} catalogCode: ${catalogCode}`
13
- );
14
-
15
- if (!process?.env?.FPI_PIPEDREAM_ALGOLIA) {
16
- log(
17
- `FPI PIPEDREAM ALGOLIA environment variable not found, reindex algolia from Pipedream cannot be started!`,
18
- "WARN"
19
- );
20
- return;
21
- }
22
-
23
- axios.post(process.env.FPI_PIPEDREAM_ALGOLIA, {
24
- isReindexByImport: true,
25
- reindexType,
26
- catalogCode,
27
- });
28
- };