pim-import 2.57.0 → 2.59.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.
@@ -30,6 +30,7 @@ import {
30
30
  keysToLowerCase,
31
31
  } from "../utils";
32
32
  import { getSubFamilySlugDetails } from "../pim/methods/subfamilies";
33
+ import { removeProductObject } from "../algolia/products";
33
34
 
34
35
  export type Config = {
35
36
  accessToken: string;
@@ -1296,3 +1297,38 @@ export const createWrapperImgix = async (
1296
1297
 
1297
1298
  return wrapperImgix;
1298
1299
  };
1300
+
1301
+ /**
1302
+ * Archive Entry
1303
+ *
1304
+ * @param entry
1305
+ * @param isProduct
1306
+ * @returns
1307
+ */
1308
+ export const archiveEntry = async (
1309
+ entry: Entry,
1310
+ isProduct: boolean = false
1311
+ ) => {
1312
+ if (!entry.isArchived()) {
1313
+ if (entry.isPublished()) {
1314
+ log(`Unpublish entry ${entry.sys.id}`);
1315
+ entry = await entry.unpublish();
1316
+ }
1317
+ log(`Archive entry ${entry.sys.id}`);
1318
+ entry = await entry.archive();
1319
+
1320
+ if (isProduct) {
1321
+ const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
1322
+ const recordObjectId = entry.fields.code[defEnvLocaleCode];
1323
+ if (recordObjectId) {
1324
+ await removeProductObject(recordObjectId);
1325
+ } else {
1326
+ log(`recordObjectId not found`, "WARN");
1327
+ }
1328
+ }
1329
+ } else {
1330
+ log(`Entry ${entry.sys.id} is already archived`);
1331
+ }
1332
+
1333
+ return entry;
1334
+ };
@@ -23,6 +23,8 @@ export const dailyProductsUpdate = async (
23
23
  s3FilePath: string = ""
24
24
  ): Promise<PaginationResults> => {
25
25
  const timeStart = new Date();
26
+ offset = Number(offset);
27
+ limit = Number(limit);
26
28
  log(
27
29
  `dailyProductsUpdate - catalog: ${catalog} day: ${day} offset: ${offset} limit: ${limit} s3FilePath: ${s3FilePath}`,
28
30
  "INFO"
@@ -31,8 +33,8 @@ export const dailyProductsUpdate = async (
31
33
  if (!s3FilePath) {
32
34
  const s3Path = await getStaticDailyProducts(catalog, day, true);
33
35
  return {
34
- offset: Number(offset),
35
- limit: Number(limit),
36
+ offset,
37
+ limit,
36
38
  completed: !s3Path,
37
39
  s3FilePath: s3Path,
38
40
  };
@@ -62,8 +64,8 @@ export const dailyProductsUpdate = async (
62
64
  log(`Request time: ${seconds} seconds`);
63
65
 
64
66
  return {
65
- offset: Number(offset) + Number(limit),
66
- limit: Number(limit),
67
+ offset: offset + limit,
68
+ limit,
67
69
  completed: limit === -1 || limit > updated,
68
70
  s3FilePath,
69
71
  total: JSONData.length,
@@ -30,6 +30,7 @@ import {
30
30
  getDictionaryLocaleValue,
31
31
  getDictionaryJson,
32
32
  getAllEntries,
33
+ archiveEntry,
33
34
  } from "../../libs/contentful";
34
35
  import type {
35
36
  Entry,
@@ -294,24 +295,11 @@ const notVisibleToWebProduct = async (code: string): Promise<void> => {
294
295
  const pageId = getProductPageIdByCode(productEntry.sys.id);
295
296
 
296
297
  log("The product exists, I proceed to archive it");
297
- if (!productEntry.isArchived()) {
298
- if (productEntry.isPublished()) {
299
- productEntry = await productEntry.unpublish();
300
- }
301
- productEntry = await productEntry.archive();
302
- }
298
+ productEntry = await archiveEntry(productEntry, true);
303
299
  // page
304
300
  let pageEntry = await getEntryByID(pageId, "page");
305
301
  if (pageEntry) {
306
- if (!pageEntry.isArchived()) {
307
- log("The product page exists, I proceed to archive it");
308
- if (pageEntry.isPublished()) {
309
- pageEntry = await pageEntry.unpublish();
310
- }
311
- pageEntry = await pageEntry.archive();
312
- } else {
313
- log("The product page exists, but is already archived");
314
- }
302
+ pageEntry = await archiveEntry(pageEntry);
315
303
  }
316
304
  } else {
317
305
  log("The product has never been imported", "WARN");
@@ -1506,6 +1494,8 @@ export const audit = async (
1506
1494
  limit: number = 150,
1507
1495
  s3FilePath: string = ""
1508
1496
  ) => {
1497
+ offset = Number(offset);
1498
+ limit = Number(limit);
1509
1499
  const timeStart = new Date();
1510
1500
  log(`audit - lastModified: ${lastModified} catalog: ${catalog}`, "INFO");
1511
1501
 
@@ -1515,8 +1505,8 @@ export const audit = async (
1515
1505
  if (!allAudit) {
1516
1506
  log(`No audits were found to process for the date ${lastModified}`);
1517
1507
  return {
1518
- offset: Number(offset),
1519
- limit: Number(limit),
1508
+ offset,
1509
+ limit,
1520
1510
  completed: true,
1521
1511
  s3FilePath: "",
1522
1512
  total: 0,
@@ -1567,7 +1557,7 @@ export const audit = async (
1567
1557
  log(
1568
1558
  `No products found between offset: ${offset} and limit: ${limit}. Total: ${total}`
1569
1559
  );
1570
- const nextOffset = Number(offset) + Number(limit);
1560
+ const nextOffset = offset + limit;
1571
1561
  const completed = limit === -1 || nextOffset >= total;
1572
1562
  if (completed) {
1573
1563
  log(`Audit completed`);
@@ -1579,7 +1569,7 @@ export const audit = async (
1579
1569
 
1580
1570
  return {
1581
1571
  offset: nextOffset,
1582
- limit: Number(limit),
1572
+ limit: limit,
1583
1573
  completed,
1584
1574
  s3FilePath,
1585
1575
  total,
@@ -1652,16 +1642,7 @@ export const audit = async (
1652
1642
  } else if (["PRODUCT_UNPUBLISH", "PRODUCT_WEBOFF"].includes(audit.what)) {
1653
1643
  log(`Set the product status as archive...`);
1654
1644
  // Set the product status as archive
1655
- if (!productEntry.isArchived()) {
1656
- if (productEntry.isPublished()) {
1657
- log(`Unpublish product ${audit.product}`);
1658
- productEntry = await productEntry.unpublish();
1659
- }
1660
- log(`Archive product ${audit.product}`);
1661
- productEntry = await productEntry.archive();
1662
- } else {
1663
- log(`Product ${productEntry.sys.id} is already archived`);
1664
- }
1645
+ productEntry = await archiveEntry(productEntry, true);
1665
1646
  if (pageEntryFrom?.fields) {
1666
1647
  if (audit.upgradeProduct && audit.upgradeProduct !== "0") {
1667
1648
  log(
@@ -1690,16 +1671,7 @@ export const audit = async (
1690
1671
  }
1691
1672
  }
1692
1673
 
1693
- if (!pageEntryFrom.isArchived()) {
1694
- if (pageEntryFrom.isPublished()) {
1695
- log(`Unpublish page ${pageEntryFrom.sys.id}`);
1696
- pageEntryFrom = await pageEntryFrom.unpublish();
1697
- }
1698
- pageEntryFrom = await pageEntryFrom.archive();
1699
- log(`${pageEntryFrom.sys.id} page archived`);
1700
- } else {
1701
- log(`${pageEntryFrom.sys.id} page is already archived`);
1702
- }
1674
+ pageEntryFrom = await archiveEntry(pageEntryFrom);
1703
1675
  } else {
1704
1676
  log(`${pageEntryFromId} page from not found`);
1705
1677
  }
@@ -1710,7 +1682,7 @@ export const audit = async (
1710
1682
  }
1711
1683
  }
1712
1684
 
1713
- const nextOffset = Number(offset) + Number(limit);
1685
+ const nextOffset = offset + limit;
1714
1686
 
1715
1687
  const tEnd = new Date();
1716
1688
  const secs = secondBetweenTwoDate(timeStart, tEnd);
@@ -1718,7 +1690,7 @@ export const audit = async (
1718
1690
 
1719
1691
  return {
1720
1692
  offset: nextOffset,
1721
- limit: Number(limit),
1693
+ limit,
1722
1694
  completed: limit === -1 || count >= total,
1723
1695
  s3FilePath,
1724
1696
  total,
@@ -1731,8 +1703,8 @@ export const audit = async (
1731
1703
  log(`Request time: ${secs} seconds`);
1732
1704
 
1733
1705
  return {
1734
- offset: Number(offset),
1735
- limit: Number(limit),
1706
+ offset: offset,
1707
+ limit: limit,
1736
1708
  completed: true,
1737
1709
  s3FilePath,
1738
1710
  };