pim-import 4.12.3 → 4.13.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.
@@ -325,19 +325,22 @@ const notVisibleToWebProduct = async (code: string): Promise<void> => {
325
325
  }
326
326
  };
327
327
 
328
- const setHideInRegionField = async (
329
- productEntry: Entry,
328
+ export const setHideInRegionField = async (
329
+ destinations: string[],
330
330
  pageData: CreateEntryProps
331
331
  ) => {
332
332
  const env = await getEnvironment();
333
333
  const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
334
334
 
335
- const productRegions = productEntry?.fields?.productFields?.[
336
- defEnvLocaleCode
337
- ]?.destinations
338
- ?.filter((item: any) => item.code.includes("PROFESSIONAL_"))
335
+ const productRegions = destinations
336
+ ?.filter(
337
+ (item: any) =>
338
+ item?.code?.includes("PROFESSIONAL_") || item?.includes("PROFESSIONAL_")
339
+ )
339
340
  .map((item: any) => {
340
- const region = item?.code?.replace("PROFESSIONAL_", "")?.toLowerCase();
341
+ const region =
342
+ item?.code?.replace("PROFESSIONAL_", "")?.toLowerCase() ||
343
+ item?.replace("PROFESSIONAL_", "")?.toLowerCase();
341
344
  return region === "china" ? "cn" : region;
342
345
  });
343
346
 
@@ -354,6 +357,7 @@ const setHideInRegionField = async (
354
357
  let count = 0;
355
358
  for (const item of items) {
356
359
  const region = item?.fields?.region?.[defEnvLocaleCode];
360
+
357
361
  if (!productRegions.includes(region)) {
358
362
  log(`Hide in region: ${region}`);
359
363
  pageData.fields = await addToRelationFields(
@@ -382,6 +386,7 @@ const getProductPageData = async (
382
386
  productEntry: Entry,
383
387
  productPageEntry: Entry
384
388
  ): Promise<CreateEntryProps> => {
389
+ const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
385
390
  const pageData: CreateEntryProps = {
386
391
  fields: productPageEntry?.fields || {},
387
392
  };
@@ -400,7 +405,9 @@ const getProductPageData = async (
400
405
  );
401
406
 
402
407
  // hideInRegions
403
- pageData.fields = await setHideInRegionField(productEntry, pageData);
408
+ const destinations =
409
+ productEntry?.fields?.productFields?.[defEnvLocaleCode]?.destinations;
410
+ pageData.fields = await setHideInRegionField(destinations, pageData);
404
411
  return pageData;
405
412
  };
406
413
 
@@ -1066,10 +1073,14 @@ const getProductData = async (
1066
1073
  );
1067
1074
 
1068
1075
  // Destinations
1069
- if(productDetails?.destinations?.length){
1076
+ if (productDetails?.destinations?.length) {
1070
1077
  log(`set destinations`);
1071
- data.fields = await addFieldValue(data, "destinations", productDetails.destinations.map(item => item.code));
1072
- }else{
1078
+ data.fields = await addFieldValue(
1079
+ data,
1080
+ "destinations",
1081
+ productDetails.destinations.map((item) => item.code)
1082
+ );
1083
+ } else {
1073
1084
  log(`destinations not found`, "WARN");
1074
1085
  }
1075
1086
 
@@ -1631,7 +1642,15 @@ export const getAllProductEntriesByCatalog = async (
1631
1642
  return allItems;
1632
1643
  };
1633
1644
 
1634
- const productAudit = async (audit: Audit, productEntries: Entry[], catalog: AvailableCatalogs, defaultEnvironmentLocaleCode: string, current: number, allAudit: Audit[], productPageEntries: Entry[]) => {
1645
+ const productAudit = async (
1646
+ audit: Audit,
1647
+ productEntries: Entry[],
1648
+ catalog: AvailableCatalogs,
1649
+ defaultEnvironmentLocaleCode: string,
1650
+ current: number,
1651
+ allAudit: Audit[],
1652
+ productPageEntries: Entry[]
1653
+ ) => {
1635
1654
  log(`Search product entry with id ${audit.product}...`);
1636
1655
  let productEntry = productEntries.find(
1637
1656
  (currentEntry) =>
@@ -1653,7 +1672,7 @@ const productAudit = async (audit: Audit, productEntries: Entry[], catalog: Avai
1653
1672
  const progress = Math.floor((++current / allAudit.length) * 100);
1654
1673
  serverUtils.updateProgress(progress);
1655
1674
  }
1656
- return {current, continue: true}
1675
+ return { current, continue: true };
1657
1676
  }
1658
1677
 
1659
1678
  log(`Founded product with id ${productEntry.sys.id}`);
@@ -1671,17 +1690,14 @@ const productAudit = async (audit: Audit, productEntries: Entry[], catalog: Avai
1671
1690
  }
1672
1691
 
1673
1692
  log(`Get product catalogs...`);
1674
- const productCatalogs: AvailableCatalogs[] =
1675
- productEntry?.fields?.catalogs?.[defaultEnvironmentLocaleCode].map(
1676
- (entryCatalog: FieldItem) => {
1677
- return entryCatalog.sys.id;
1678
- }
1679
- );
1693
+ const productCatalogs: AvailableCatalogs[] = productEntry?.fields?.catalogs?.[
1694
+ defaultEnvironmentLocaleCode
1695
+ ].map((entryCatalog: FieldItem) => {
1696
+ return entryCatalog.sys.id;
1697
+ });
1680
1698
 
1681
1699
  if (catalog && !productCatalogs.includes(catalog)) {
1682
- log(
1683
- `Product ${audit.product} does not belong to the ${catalog} catalog`
1684
- );
1700
+ log(`Product ${audit.product} does not belong to the ${catalog} catalog`);
1685
1701
  } else if (["PRODUCT_UNPUBLISH", "PRODUCT_WEBOFF"].includes(audit.what)) {
1686
1702
  log(`Set the product status as archive...`);
1687
1703
  // Set the product status as archive
@@ -1699,11 +1715,7 @@ const productAudit = async (audit: Audit, productEntries: Entry[], catalog: Avai
1699
1715
  `Creating redirect from ${audit.product} to ${audit.upgradeProduct}`
1700
1716
  );
1701
1717
  const pageEntryToId = getProductPageIdByCode(audit.upgradeProduct);
1702
- const pageEntryTo = await getEntryByID(
1703
- pageEntryToId,
1704
- "page",
1705
- "sys.id"
1706
- );
1718
+ const pageEntryTo = await getEntryByID(pageEntryToId, "page", "sys.id");
1707
1719
 
1708
1720
  if (pageEntryTo) {
1709
1721
  // Save redirect
@@ -1730,7 +1742,7 @@ const productAudit = async (audit: Audit, productEntries: Entry[], catalog: Avai
1730
1742
  for (const item of audit?.catalogs) {
1731
1743
  if (!item?.where) {
1732
1744
  log(
1733
- `catalogs.where field not exists. Product: ${audit.product} `,
1745
+ `catalogs.where field not exists. Product: ${audit.product} `,
1734
1746
  "WARN"
1735
1747
  );
1736
1748
  } else {
@@ -1763,8 +1775,7 @@ const productAudit = async (audit: Audit, productEntries: Entry[], catalog: Avai
1763
1775
  );
1764
1776
  }
1765
1777
  if (item?.models) {
1766
- const modelsFieldKey =
1767
- "models" + capitalizeFirstLetter(item.where);
1778
+ const modelsFieldKey = "models" + capitalizeFirstLetter(item.where);
1768
1779
  productEntry.fields = await removeFromRelationFields(
1769
1780
  productEntry,
1770
1781
  modelsFieldKey,
@@ -1792,15 +1803,20 @@ const productAudit = async (audit: Audit, productEntries: Entry[], catalog: Avai
1792
1803
  }
1793
1804
  }
1794
1805
  } else {
1795
- log(
1796
- `It has not yet been defined how to process the state ${audit.what}`
1797
- );
1806
+ log(`It has not yet been defined how to process the state ${audit.what}`);
1798
1807
  }
1799
1808
 
1800
- return {current, continue: false}
1801
- }
1809
+ return { current, continue: false };
1810
+ };
1802
1811
 
1803
- const familyAudit = async (audit: Audit, familyEntries: Entry[], catalog: AvailableCatalogs, defaultEnvironmentLocaleCode: string, current: number, allAudit: Audit[]) => {
1812
+ const familyAudit = async (
1813
+ audit: Audit,
1814
+ familyEntries: Entry[],
1815
+ catalog: AvailableCatalogs,
1816
+ defaultEnvironmentLocaleCode: string,
1817
+ current: number,
1818
+ allAudit: Audit[]
1819
+ ) => {
1804
1820
  log(`Search family entry with id ${audit.product}...`);
1805
1821
  let familyEntry = familyEntries.find(
1806
1822
  (currentEntry) =>
@@ -1822,35 +1838,34 @@ const familyAudit = async (audit: Audit, familyEntries: Entry[], catalog: Availa
1822
1838
  const progress = Math.floor((++current / allAudit.length) * 100);
1823
1839
  serverUtils.updateProgress(progress);
1824
1840
  }
1825
- return {current, continue: true}
1841
+ return { current, continue: true };
1826
1842
  }
1827
1843
 
1828
1844
  log(`Founded family with id ${familyEntry.sys.id}`);
1829
1845
 
1830
1846
  log(`Get family catalogs...`);
1831
- const familyCatalogs: AvailableCatalogs[] =
1832
- familyEntry?.fields?.catalogs?.[defaultEnvironmentLocaleCode].map(
1833
- (entryCatalog: FieldItem) => {
1834
- return entryCatalog.sys.id;
1835
- }
1836
- );
1847
+ const familyCatalogs: AvailableCatalogs[] = familyEntry?.fields?.catalogs?.[
1848
+ defaultEnvironmentLocaleCode
1849
+ ].map((entryCatalog: FieldItem) => {
1850
+ return entryCatalog.sys.id;
1851
+ });
1837
1852
 
1838
1853
  if (catalog && !familyCatalogs.includes(catalog)) {
1839
- log(
1840
- `Family ${audit.product} does not belong to the ${catalog} catalog`
1841
- );
1854
+ log(`Family ${audit.product} does not belong to the ${catalog} catalog`);
1842
1855
  } else if (audit.what === "REMOVE_FAMILY_RELATIONS") {
1843
1856
  for (const item of audit?.catalogs) {
1844
1857
  if (!item?.where) {
1845
1858
  log(
1846
- `catalogs.where field not exists. Family: ${audit.product} `,
1859
+ `catalogs.where field not exists. Family: ${audit.product} `,
1847
1860
  "WARN"
1848
1861
  );
1849
1862
  } else {
1850
- if(item.where === "DESIGNERS" && item?.codes){
1851
- const designers = item.codes.split(',')
1852
- for(const designer of designers){
1853
- log(`Remove ${designer} designer to ${familyEntry.sys.id} family if exists`)
1863
+ if (item.where === "DESIGNERS" && item?.codes) {
1864
+ const designers = item.codes.split(",");
1865
+ for (const designer of designers) {
1866
+ log(
1867
+ `Remove ${designer} designer to ${familyEntry.sys.id} family if exists`
1868
+ );
1854
1869
  familyEntry.fields = await removeFromRelationFields(
1855
1870
  familyEntry,
1856
1871
  "designer",
@@ -1863,15 +1878,20 @@ const familyAudit = async (audit: Audit, familyEntries: Entry[], catalog: Availa
1863
1878
  }
1864
1879
  }
1865
1880
  } else {
1866
- log(
1867
- `It has not yet been defined how to process the state ${audit.what}`
1868
- );
1881
+ log(`It has not yet been defined how to process the state ${audit.what}`);
1869
1882
  }
1870
1883
 
1871
- return {current, continue: false}
1872
- }
1884
+ return { current, continue: false };
1885
+ };
1873
1886
 
1874
- const subFamilyAudit = async (audit: Audit, subfamilyEntries: Entry[], catalog: AvailableCatalogs, defaultEnvironmentLocaleCode: string, current: number, allAudit: Audit[]) => {
1887
+ const subFamilyAudit = async (
1888
+ audit: Audit,
1889
+ subfamilyEntries: Entry[],
1890
+ catalog: AvailableCatalogs,
1891
+ defaultEnvironmentLocaleCode: string,
1892
+ current: number,
1893
+ allAudit: Audit[]
1894
+ ) => {
1875
1895
  log(`Search subFamily entry with id ${audit.product}...`);
1876
1896
  let subFamilyEntry = subfamilyEntries.find(
1877
1897
  (currentEntry) =>
@@ -1893,30 +1913,31 @@ const subFamilyAudit = async (audit: Audit, subfamilyEntries: Entry[], catalog:
1893
1913
  const progress = Math.floor((++current / allAudit.length) * 100);
1894
1914
  serverUtils.updateProgress(progress);
1895
1915
  }
1896
- return {current, continue: true}
1916
+ return { current, continue: true };
1897
1917
  }
1898
1918
 
1899
1919
  log(`Founded subFamily with id ${subFamilyEntry.sys.id}`);
1900
1920
 
1901
1921
  log(`Get subFamily catalogs...`);
1902
- const subFamilyCatalog: AvailableCatalogs = subFamilyEntry?.fields?.catalog?.[defaultEnvironmentLocaleCode].sys.id;
1922
+ const subFamilyCatalog: AvailableCatalogs =
1923
+ subFamilyEntry?.fields?.catalog?.[defaultEnvironmentLocaleCode].sys.id;
1903
1924
 
1904
1925
  if (catalog && subFamilyCatalog !== catalog) {
1905
- log(
1906
- `SubFamily ${audit.product} does not belong to the ${catalog} catalog`
1907
- );
1926
+ log(`SubFamily ${audit.product} does not belong to the ${catalog} catalog`);
1908
1927
  } else if (audit.what === "REMOVE_SUBFAMILY_RELATIONS") {
1909
1928
  for (const item of audit?.catalogs) {
1910
1929
  if (!item?.where) {
1911
1930
  log(
1912
- `catalogs.where field not exists. SubFamily: ${audit.product} `,
1931
+ `catalogs.where field not exists. SubFamily: ${audit.product} `,
1913
1932
  "WARN"
1914
1933
  );
1915
1934
  } else {
1916
- if(item.where === "DESIGNERS" && item?.codes){
1917
- const designers = item.codes.split(',')
1918
- for(const designer of designers){
1919
- log(`Remove ${designer} designer to ${subFamilyEntry.sys.id} subFamily if exists`)
1935
+ if (item.where === "DESIGNERS" && item?.codes) {
1936
+ const designers = item.codes.split(",");
1937
+ for (const designer of designers) {
1938
+ log(
1939
+ `Remove ${designer} designer to ${subFamilyEntry.sys.id} subFamily if exists`
1940
+ );
1920
1941
  subFamilyEntry.fields = await removeFromRelationFields(
1921
1942
  subFamilyEntry,
1922
1943
  "designer",
@@ -1929,13 +1950,11 @@ const subFamilyAudit = async (audit: Audit, subfamilyEntries: Entry[], catalog:
1929
1950
  }
1930
1951
  }
1931
1952
  } else {
1932
- log(
1933
- `It has not yet been defined how to process the state ${audit.what}`
1934
- );
1953
+ log(`It has not yet been defined how to process the state ${audit.what}`);
1935
1954
  }
1936
1955
 
1937
- return {current, continue: false}
1938
- }
1956
+ return { current, continue: false };
1957
+ };
1939
1958
 
1940
1959
  /**
1941
1960
  *
@@ -2002,10 +2021,20 @@ export const audit = async (
2002
2021
  const defaultEnvironmentLocaleCode =
2003
2022
  await getEnvironmentDefaultLocaleCode();
2004
2023
 
2005
- const productAuditWhat = ["PRODUCT_UNPUBLISH", "PRODUCT_WEBOFF","REMOVE_PRODUCT_RELATIONS"]
2006
- const productCodes = allAudit.filter(item => productAuditWhat.includes(item.what)).map((audit) => audit.product);
2007
- const familyCodes = allAudit.filter(item => item.what === "REMOVE_FAMILY_RELATIONS").map((audit) => audit.product);
2008
- const subFamilyCodes = allAudit.filter(item => item.what === "REMOVE_SUBFAMILY_RELATIONS").map((audit) => audit.product);
2024
+ const productAuditWhat = [
2025
+ "PRODUCT_UNPUBLISH",
2026
+ "PRODUCT_WEBOFF",
2027
+ "REMOVE_PRODUCT_RELATIONS",
2028
+ ];
2029
+ const productCodes = allAudit
2030
+ .filter((item) => productAuditWhat.includes(item.what))
2031
+ .map((audit) => audit.product);
2032
+ const familyCodes = allAudit
2033
+ .filter((item) => item.what === "REMOVE_FAMILY_RELATIONS")
2034
+ .map((audit) => audit.product);
2035
+ const subFamilyCodes = allAudit
2036
+ .filter((item) => item.what === "REMOVE_SUBFAMILY_RELATIONS")
2037
+ .map((audit) => audit.product);
2009
2038
  const otherFilters = [];
2010
2039
  if (catalog) {
2011
2040
  otherFilters.push({ key: "fields.catalogs.sys.id[in]", value: catalog });
@@ -2020,8 +2049,8 @@ export const audit = async (
2020
2049
  );
2021
2050
  log(`Founded ${productEntries.length} topicProduct`);
2022
2051
 
2023
- let familyEntries: Entry[] = []
2024
- if(familyCodes.length){
2052
+ let familyEntries: Entry[] = [];
2053
+ if (familyCodes.length) {
2025
2054
  familyEntries = await getAllEntriesByCodes(
2026
2055
  familyCodes,
2027
2056
  "topicFamily",
@@ -2032,8 +2061,8 @@ export const audit = async (
2032
2061
  }
2033
2062
  log(`Founded ${familyEntries.length} topicFamily`);
2034
2063
 
2035
- let subFamilyEntries: Entry[] = []
2036
- if(subFamilyCodes.length){
2064
+ let subFamilyEntries: Entry[] = [];
2065
+ if (subFamilyCodes.length) {
2037
2066
  subFamilyEntries = await getAllEntriesByCodes(
2038
2067
  subFamilyCodes,
2039
2068
  "topicSubFamily",
@@ -2044,7 +2073,11 @@ export const audit = async (
2044
2073
  }
2045
2074
  log(`Founded ${subFamilyEntries.length} topicSubFamily`);
2046
2075
 
2047
- if (!productEntries.length && !familyEntries.length && !subFamilyEntries.length) {
2076
+ if (
2077
+ !productEntries.length &&
2078
+ !familyEntries.length &&
2079
+ !subFamilyEntries.length
2080
+ ) {
2048
2081
  log(
2049
2082
  `No items found between offset: ${offset} and limit: ${limit}. Total: ${total}`
2050
2083
  );
@@ -2092,23 +2125,45 @@ export const audit = async (
2092
2125
  log(`${++count} of ${total}`);
2093
2126
  log(`I process the item ${audit.product} with status ${audit.what}`);
2094
2127
 
2095
- if(productAuditWhat.includes(audit.what)){
2096
- const result = await productAudit(audit, productEntries, catalog, defaultEnvironmentLocaleCode, current, allAudit, productPageEntries)
2097
- current = result.current
2098
- if(result.continue){
2099
- continue
2128
+ if (productAuditWhat.includes(audit.what)) {
2129
+ const result = await productAudit(
2130
+ audit,
2131
+ productEntries,
2132
+ catalog,
2133
+ defaultEnvironmentLocaleCode,
2134
+ current,
2135
+ allAudit,
2136
+ productPageEntries
2137
+ );
2138
+ current = result.current;
2139
+ if (result.continue) {
2140
+ continue;
2100
2141
  }
2101
- }else if(audit.what === "REMOVE_FAMILY_RELATIONS"){
2102
- const result = await familyAudit(audit, familyEntries, catalog, defaultEnvironmentLocaleCode, current, allAudit)
2103
- current = result.current
2104
- if(result.continue){
2105
- continue
2142
+ } else if (audit.what === "REMOVE_FAMILY_RELATIONS") {
2143
+ const result = await familyAudit(
2144
+ audit,
2145
+ familyEntries,
2146
+ catalog,
2147
+ defaultEnvironmentLocaleCode,
2148
+ current,
2149
+ allAudit
2150
+ );
2151
+ current = result.current;
2152
+ if (result.continue) {
2153
+ continue;
2106
2154
  }
2107
- }else if(audit.what === "REMOVE_SUBFAMILY_RELATIONS"){
2108
- const result = await subFamilyAudit(audit, subFamilyEntries, catalog, defaultEnvironmentLocaleCode, current, allAudit)
2109
- current = result.current
2110
- if(result.continue){
2111
- continue
2155
+ } else if (audit.what === "REMOVE_SUBFAMILY_RELATIONS") {
2156
+ const result = await subFamilyAudit(
2157
+ audit,
2158
+ subFamilyEntries,
2159
+ catalog,
2160
+ defaultEnvironmentLocaleCode,
2161
+ current,
2162
+ allAudit
2163
+ );
2164
+ current = result.current;
2165
+ if (result.continue) {
2166
+ continue;
2112
2167
  }
2113
2168
  }
2114
2169
 
@@ -2130,7 +2185,8 @@ export const audit = async (
2130
2185
  completed: limit === -1 || count >= total,
2131
2186
  s3FilePath,
2132
2187
  total,
2133
- processedEntries: productEntries.length + familyEntries.length + subFamilyEntries.length,
2188
+ processedEntries:
2189
+ productEntries.length + familyEntries.length + subFamilyEntries.length,
2134
2190
  };
2135
2191
  } else {
2136
2192
  log(`Execution completed`);
@@ -2890,44 +2946,52 @@ export const reimportAuditProducts = async (
2890
2946
  };
2891
2947
  };
2892
2948
 
2893
-
2894
2949
  export const populateDestinations = async (offset: number, limit: number) => {
2895
2950
  const env = await getEnvironment();
2896
2951
  const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
2897
2952
 
2898
2953
  const opts = {
2899
- content_type: 'topicProduct',
2954
+ content_type: "topicProduct",
2900
2955
  skip: offset,
2901
2956
  limit,
2902
2957
  locale: defEnvLocaleCode,
2903
2958
  // select: 'sys.id,fields',
2904
2959
  "sys.archivedAt[exists]": false,
2960
+ // "fields.destinations[exists]": false,
2905
2961
  };
2906
- const {items, total} = await env.getEntries(opts);
2962
+
2963
+ const { items, total } = await env.getEntries(opts);
2907
2964
 
2908
2965
  let count: number = offset;
2909
2966
  for (let productEntry of items) {
2910
- log(`${++count} of ${total}`);
2911
- log(`Product: ${productEntry.sys.id}`);
2912
- const destinations = productEntry.fields.productFields[defEnvLocaleCode]?.destinations?.map((destination:any) => destination.code) || []
2913
-
2914
- if(destinations.length){
2915
- log(`Set destinations: ${destinations.join(', ')}`)
2916
- productEntry.fields = await addFieldValue(productEntry, "destinations", destinations)
2917
- productEntry = await productEntry.update();
2918
- }else{
2919
- log(`No destinations found.`, "WARN")
2967
+ log(`${++count} of ${total}`);
2968
+ log(`Product: ${productEntry.sys.id}`);
2969
+ const destinations =
2970
+ productEntry.fields.productFields[defEnvLocaleCode]?.destinations?.map(
2971
+ (destination: any) => destination.code
2972
+ ) || [];
2973
+
2974
+ if (destinations.length) {
2975
+ log(`Set destinations: ${destinations.join(", ")}`);
2976
+ productEntry.fields = await addFieldValue(
2977
+ productEntry,
2978
+ "destinations",
2979
+ destinations
2980
+ );
2981
+ productEntry = await productEntry.update();
2982
+ } else {
2983
+ log(`No destinations found.`, "WARN");
2920
2984
  }
2921
2985
 
2922
- if (productEntry.isPublished()) {
2923
- try {
2924
- productEntry = await productEntry.publish();
2925
- } catch (err) {
2926
- log(`Cannot publish entry.`);
2927
- log(err);
2928
- }
2929
- }
2986
+ if (productEntry.isPublished()) {
2987
+ try {
2988
+ productEntry = await productEntry.publish();
2989
+ } catch (err) {
2990
+ log(`Cannot publish entry.`);
2991
+ log(err);
2992
+ }
2930
2993
  }
2994
+ }
2931
2995
 
2932
- return {completed: total === count + offset, offset, limit}
2933
- }
2996
+ return { completed: !total || total === count + offset, offset, limit };
2997
+ };
@@ -37,6 +37,7 @@ import {
37
37
  import { updateSubFamiliesRelToEntry, getCategoryTopicCode } from "./catalogs";
38
38
  import { pageResponse } from "../../algolia/families";
39
39
  import { addDesignerData } from "./designers";
40
+ import { setHideInRegionField } from "./products";
40
41
 
41
42
  const getComponentModelPagesData = async (
42
43
  componentID: string,
@@ -116,6 +117,7 @@ const getSubFamilyPageData = async (
116
117
  subFamilyEntry: Entry,
117
118
  subFamilyPageEntry: Entry
118
119
  ): Promise<CreateEntryProps> => {
120
+ const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
119
121
  const pageData: CreateEntryProps = {
120
122
  fields: subFamilyPageEntry?.fields || {},
121
123
  };
@@ -142,6 +144,10 @@ const getSubFamilyPageData = async (
142
144
  true
143
145
  );
144
146
 
147
+ const destinations =
148
+ subFamilyEntry?.fields?.destinations?.[defEnvLocaleCode] || [];
149
+ pageData.fields = await setHideInRegionField(destinations, pageData);
150
+
145
151
  return pageData;
146
152
  };
147
153
 
@@ -397,18 +403,20 @@ const getTopicSubFamilyData = async (
397
403
  }
398
404
 
399
405
  // Destinations
400
- if(subFamily?.destinations?.length){
406
+ if (subFamily?.destinations?.length) {
401
407
  log(`set destinations`);
402
- data.fields = await addFieldValue(data, "destinations", subFamily.destinations);
403
- }else{
408
+ data.fields = await addFieldValue(
409
+ data,
410
+ "destinations",
411
+ subFamily.destinations
412
+ );
413
+ } else {
404
414
  log(`destinations not found`, "WARN");
405
415
  }
406
416
 
407
417
  // lastPimSyncDate
408
418
  data.fields = await addFieldValue(data, "lastPimSyncDate", getLocalISOTime());
409
419
 
410
-
411
-
412
420
  return data;
413
421
  };
414
422
 
@@ -17,6 +17,7 @@ export declare type AlgoliaFamilyRecord = {
17
17
  productFields: TopicProductFieldsResponse[];
18
18
  isNew: boolean;
19
19
  priority: number;
20
+ destinations?: string[];
20
21
  lastSyncDate: string;
21
22
  };
22
23
  export declare const reindexFamilies: (offset?: number, limit?: number, catalogCode?: AvailableCatalogs | undefined) => Promise<{
@@ -42,6 +43,7 @@ export declare const reindexFamily: (topicFamilyEntryId: string) => Promise<fals
42
43
  productFields: TopicProductFieldsResponse[];
43
44
  isNew: boolean;
44
45
  priority: number;
46
+ destinations?: string[] | undefined;
45
47
  lastSyncDate: string;
46
48
  taskID: number;
47
49
  }>;
@@ -18,6 +18,7 @@ export declare const reindexModel: (topicModelId: string) => Promise<{
18
18
  colors?: string[] | undefined;
19
19
  designer?: TopicDetailsResponse | undefined;
20
20
  lastSyncDate?: string | undefined;
21
+ destinations?: string[] | undefined;
21
22
  taskID: number;
22
23
  }>;
23
24
  export declare const reindexModels: (offset?: number, limit?: number, catalogCode?: AvailableCatalogs | undefined) => Promise<{
@@ -22,6 +22,7 @@ export declare const reindexSubFamily: (topicSubFamilyEntryId: string) => Promis
22
22
  productFields: import("../types").TopicProductFieldsResponse[];
23
23
  isNew: boolean;
24
24
  priority: number;
25
+ destinations?: string[] | undefined;
25
26
  lastSyncDate: string;
26
27
  taskID: number;
27
28
  }>;
@@ -13,6 +13,7 @@ export declare const reindexSubModel: (topicSubModelId: string) => Promise<{
13
13
  isNew?: boolean | undefined;
14
14
  priority?: number | undefined;
15
15
  productCounter?: number | undefined;
16
+ destinations?: string[] | undefined;
16
17
  lastSyncDate?: string | undefined;
17
18
  taskID: number;
18
19
  }>;
@@ -1,8 +1,10 @@
1
1
  import { ProductDetails } from "../../resources/ProductDetails";
2
2
  import { AvailableCatalogs } from "../../types";
3
- import type { Entry } from "contentful-management/dist/typings/entities/entry";
3
+ import type { Entry, CreateEntryProps } from "contentful-management/dist/typings/entities/entry";
4
+ import { KeyValueMap } from "contentful-management/dist/typings/common-types";
4
5
  export declare type AvailableProductStatus = "To be review" | "Published" | "Unpublished";
5
6
  export declare type AvailableRelationFieldKeys = "accessories" | "accessoryOf" | "bulbOf" | "sparepartOf" | "bulbs" | "spareparts";
7
+ export declare const setHideInRegionField: (destinations: string[], pageData: CreateEntryProps) => Promise<KeyValueMap>;
6
8
  export declare const certificationFields: string[];
7
9
  export declare const excludeCertificationFieldsKeys: string[];
8
10
  export declare const getProductPageIdByCode: (productCode: string) => string;