pim-import 2.47.4 → 2.48.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/config.js +6 -0
- package/dist/algolia/config.js.map +1 -1
- package/dist/algolia/products.js +1 -156
- package/dist/algolia/products.js.map +1 -1
- package/dist/algolia/stories.js +122 -0
- package/dist/algolia/stories.js.map +1 -0
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/pim/methods/products.js +193 -1
- package/dist/pim/methods/products.js.map +1 -1
- package/package.json +1 -1
- package/src/algolia/config.ts +8 -1
- package/src/algolia/products.ts +1 -220
- package/src/algolia/stories.ts +187 -0
- package/src/index.ts +6 -0
- package/src/pim/methods/products.ts +265 -0
package/src/index.ts
CHANGED
|
@@ -36,6 +36,7 @@ export {
|
|
|
36
36
|
getAllProductEntriesByCatalog,
|
|
37
37
|
audit,
|
|
38
38
|
generateTechSpecPdf,
|
|
39
|
+
setProductAutodescription,
|
|
39
40
|
} from "./pim/methods/products";
|
|
40
41
|
// export {
|
|
41
42
|
// createOrUpdateCatalogPages,
|
|
@@ -86,6 +87,11 @@ export {
|
|
|
86
87
|
reindexProjects,
|
|
87
88
|
removeProjectObject,
|
|
88
89
|
} from "./algolia/projects";
|
|
90
|
+
export {
|
|
91
|
+
reindexStory,
|
|
92
|
+
reindexStories,
|
|
93
|
+
removeStoryObject,
|
|
94
|
+
} from "./algolia/stories";
|
|
89
95
|
export { importDownloads } from "./downloads/import";
|
|
90
96
|
export { getLocalISOTime } from "./utils";
|
|
91
97
|
export { getStaticDailyProducts } from "./pim/endpoints";
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
AvailableCatalogs,
|
|
13
13
|
CfLocalizedEntryField,
|
|
14
14
|
WrapperImageFields,
|
|
15
|
+
CfSys,
|
|
15
16
|
} from "../../types";
|
|
16
17
|
import { log } from "../../libs/logs";
|
|
17
18
|
import {
|
|
@@ -26,6 +27,8 @@ import {
|
|
|
26
27
|
addFieldValue,
|
|
27
28
|
addToRelationFields,
|
|
28
29
|
createWrapperImgix,
|
|
30
|
+
getDictionaryLocaleValue,
|
|
31
|
+
getDictionaryJson,
|
|
29
32
|
} from "../../libs/contentful";
|
|
30
33
|
import type {
|
|
31
34
|
Entry,
|
|
@@ -1757,3 +1760,265 @@ export const generateTechSpecPdf = async (topicProductId: string) => {
|
|
|
1757
1760
|
|
|
1758
1761
|
return s3Url;
|
|
1759
1762
|
};
|
|
1763
|
+
|
|
1764
|
+
const getLightModuleAutoDescriptionByProductFields = async (
|
|
1765
|
+
productFileds: any,
|
|
1766
|
+
catalogs: AvailableCatalogs[]
|
|
1767
|
+
) => {
|
|
1768
|
+
const autoDescription: any = {};
|
|
1769
|
+
const dictionaryJson = await getDictionaryJson();
|
|
1770
|
+
for (const locale of cfLocales) {
|
|
1771
|
+
if (!autoDescription?.[locale]) {
|
|
1772
|
+
autoDescription[locale] = "";
|
|
1773
|
+
}
|
|
1774
|
+
let addSeparator = false;
|
|
1775
|
+
if (productFileds?.electrical?.lampCategories) {
|
|
1776
|
+
const lampCategoriesLocalizedValues = [];
|
|
1777
|
+
for (const lampCategory of productFileds.electrical.lampCategories) {
|
|
1778
|
+
const lampCategoryLocalizedValue = await getDictionaryLocaleValue(
|
|
1779
|
+
locale,
|
|
1780
|
+
"lampCategories",
|
|
1781
|
+
lampCategory.code,
|
|
1782
|
+
"electrical",
|
|
1783
|
+
dictionaryJson
|
|
1784
|
+
);
|
|
1785
|
+
if (lampCategoryLocalizedValue) {
|
|
1786
|
+
lampCategoriesLocalizedValues.push(lampCategoryLocalizedValue);
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
if (lampCategoriesLocalizedValues.length) {
|
|
1791
|
+
if (addSeparator) {
|
|
1792
|
+
autoDescription[locale] += " - ";
|
|
1793
|
+
} else {
|
|
1794
|
+
addSeparator = true;
|
|
1795
|
+
}
|
|
1796
|
+
autoDescription[locale] += lampCategoriesLocalizedValues.join(", ");
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
if (
|
|
1801
|
+
productFileds?.electrical?.wPower &&
|
|
1802
|
+
catalogs.indexOf("ARCHITECTURAL") !== -1
|
|
1803
|
+
) {
|
|
1804
|
+
if (addSeparator) {
|
|
1805
|
+
autoDescription[locale] += " - ";
|
|
1806
|
+
} else {
|
|
1807
|
+
addSeparator = true;
|
|
1808
|
+
}
|
|
1809
|
+
autoDescription[locale] += productFileds.electrical.wPower;
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
if (
|
|
1813
|
+
productFileds?.optical?.numberOfHeads &&
|
|
1814
|
+
productFileds?.optical?.numberOfHeads > 1 &&
|
|
1815
|
+
productFileds?.photometric?.realNetFlow &&
|
|
1816
|
+
catalogs.indexOf("ARCHITECTURAL") !== -1
|
|
1817
|
+
) {
|
|
1818
|
+
if (addSeparator) {
|
|
1819
|
+
autoDescription[locale] += " - ";
|
|
1820
|
+
} else {
|
|
1821
|
+
addSeparator = true;
|
|
1822
|
+
}
|
|
1823
|
+
autoDescription[locale] +=
|
|
1824
|
+
productFileds.optical.numberOfHeads +
|
|
1825
|
+
" x " +
|
|
1826
|
+
productFileds.photometric.realNetFlow;
|
|
1827
|
+
} else if (
|
|
1828
|
+
productFileds?.photometric?.realNetFlow &&
|
|
1829
|
+
catalogs.indexOf("ARCHITECTURAL") !== -1
|
|
1830
|
+
) {
|
|
1831
|
+
if (addSeparator) {
|
|
1832
|
+
autoDescription[locale] += " - ";
|
|
1833
|
+
} else {
|
|
1834
|
+
addSeparator = true;
|
|
1835
|
+
}
|
|
1836
|
+
autoDescription[locale] += productFileds.photometric.realNetFlow;
|
|
1837
|
+
}
|
|
1838
|
+
|
|
1839
|
+
if (productFileds?.photometric?.temperatureColor?.code) {
|
|
1840
|
+
const temperatireColorLocalizedValue = await getDictionaryLocaleValue(
|
|
1841
|
+
locale,
|
|
1842
|
+
"temperatureColor",
|
|
1843
|
+
productFileds.photometric.temperatureColor.code,
|
|
1844
|
+
"photometric",
|
|
1845
|
+
dictionaryJson
|
|
1846
|
+
);
|
|
1847
|
+
if (temperatireColorLocalizedValue) {
|
|
1848
|
+
if (addSeparator) {
|
|
1849
|
+
autoDescription[locale] += " - ";
|
|
1850
|
+
} else {
|
|
1851
|
+
addSeparator = true;
|
|
1852
|
+
}
|
|
1853
|
+
autoDescription[locale] += temperatireColorLocalizedValue;
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
|
|
1857
|
+
if (productFileds?.photometric?.cri?.code) {
|
|
1858
|
+
const CriLocalizedValue = await getDictionaryLocaleValue(
|
|
1859
|
+
locale,
|
|
1860
|
+
"cri",
|
|
1861
|
+
productFileds.photometric.cri.code,
|
|
1862
|
+
"photometric",
|
|
1863
|
+
dictionaryJson
|
|
1864
|
+
);
|
|
1865
|
+
if (CriLocalizedValue) {
|
|
1866
|
+
if (addSeparator) {
|
|
1867
|
+
autoDescription[locale] += " - ";
|
|
1868
|
+
} else {
|
|
1869
|
+
addSeparator = true;
|
|
1870
|
+
}
|
|
1871
|
+
autoDescription[locale] += "CRI " + CriLocalizedValue;
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
if (
|
|
1876
|
+
productFileds?.photometric?.beam0_180 &&
|
|
1877
|
+
catalogs.indexOf("OUTDOOR") !== -1
|
|
1878
|
+
) {
|
|
1879
|
+
if (addSeparator) {
|
|
1880
|
+
autoDescription[locale] += " - ";
|
|
1881
|
+
} else {
|
|
1882
|
+
addSeparator = true;
|
|
1883
|
+
}
|
|
1884
|
+
autoDescription[locale] += "BEAM " + productFileds.photometric.beam0_180;
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
return autoDescription;
|
|
1889
|
+
};
|
|
1890
|
+
|
|
1891
|
+
const getOtherAutoDescriptionByProductFields = async (productFileds: any) => {
|
|
1892
|
+
const autoDescription: any = {};
|
|
1893
|
+
const dictionaryJson = await getDictionaryJson();
|
|
1894
|
+
for (const locale of cfLocales) {
|
|
1895
|
+
if (!autoDescription?.[locale]) {
|
|
1896
|
+
autoDescription[locale] = "";
|
|
1897
|
+
}
|
|
1898
|
+
let addSeparator = false;
|
|
1899
|
+
// Profile and others
|
|
1900
|
+
if (productFileds?.physical?.length) {
|
|
1901
|
+
autoDescription[locale] += "Length: " + productFileds.physical.length;
|
|
1902
|
+
addSeparator = true;
|
|
1903
|
+
}
|
|
1904
|
+
|
|
1905
|
+
if (productFileds?.mountings) {
|
|
1906
|
+
const mountingsLocalizedValues = [];
|
|
1907
|
+
for (const mounting of productFileds.mountings) {
|
|
1908
|
+
const mountingLocalizedValue = await getDictionaryLocaleValue(
|
|
1909
|
+
locale,
|
|
1910
|
+
"mountings",
|
|
1911
|
+
mounting.code,
|
|
1912
|
+
"",
|
|
1913
|
+
dictionaryJson
|
|
1914
|
+
);
|
|
1915
|
+
if (mountingLocalizedValue) {
|
|
1916
|
+
mountingsLocalizedValues.push(mountingLocalizedValue);
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
if (addSeparator) {
|
|
1921
|
+
autoDescription[locale] += " - ";
|
|
1922
|
+
} else {
|
|
1923
|
+
addSeparator = true;
|
|
1924
|
+
}
|
|
1925
|
+
autoDescription[locale] += mountingsLocalizedValues.join(", ");
|
|
1926
|
+
}
|
|
1927
|
+
}
|
|
1928
|
+
|
|
1929
|
+
return autoDescription;
|
|
1930
|
+
};
|
|
1931
|
+
|
|
1932
|
+
/**
|
|
1933
|
+
* Get topicProduct autoDescription
|
|
1934
|
+
*
|
|
1935
|
+
* @param topicProduct
|
|
1936
|
+
* @returns
|
|
1937
|
+
*/
|
|
1938
|
+
const getTopicProductAutodescription = async (topicProduct: Entry) => {
|
|
1939
|
+
const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
1940
|
+
let catalogs = topicProduct?.fields?.catalogs?.[defaultEnvironmentLocaleCode];
|
|
1941
|
+
if (catalogs) {
|
|
1942
|
+
catalogs = catalogs.map((catalog: CfSys) => catalog.sys.id);
|
|
1943
|
+
}
|
|
1944
|
+
const productLineCode =
|
|
1945
|
+
topicProduct?.fields?.productLine?.[defaultEnvironmentLocaleCode]?.sys?.id;
|
|
1946
|
+
const productFileds =
|
|
1947
|
+
topicProduct?.fields?.productFields?.[defaultEnvironmentLocaleCode];
|
|
1948
|
+
|
|
1949
|
+
let autoDescription: any = {};
|
|
1950
|
+
switch (productLineCode) {
|
|
1951
|
+
case "PLINE6": // Soft Plate
|
|
1952
|
+
case "PLINE5": // Light Bulb
|
|
1953
|
+
case "PLINE3": // Driver
|
|
1954
|
+
case "PLINE2": // Accessory
|
|
1955
|
+
// post_content
|
|
1956
|
+
autoDescription = topicProduct?.fields?.description;
|
|
1957
|
+
break;
|
|
1958
|
+
case "PLINE1": // Light Module
|
|
1959
|
+
autoDescription = await getLightModuleAutoDescriptionByProductFields(
|
|
1960
|
+
productFileds,
|
|
1961
|
+
catalogs
|
|
1962
|
+
);
|
|
1963
|
+
|
|
1964
|
+
break;
|
|
1965
|
+
default:
|
|
1966
|
+
autoDescription = await getOtherAutoDescriptionByProductFields(
|
|
1967
|
+
productFileds
|
|
1968
|
+
);
|
|
1969
|
+
|
|
1970
|
+
break;
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
return autoDescription;
|
|
1974
|
+
};
|
|
1975
|
+
|
|
1976
|
+
export const setProductAutodescription = async (
|
|
1977
|
+
catalog: AvailableCatalogs,
|
|
1978
|
+
offset: number = 0,
|
|
1979
|
+
limit: number = 100
|
|
1980
|
+
) => {
|
|
1981
|
+
log(
|
|
1982
|
+
`setProductAutodescription - catalog: ${catalog}, offset: ${offset}, limit: ${limit}`,
|
|
1983
|
+
"INFO"
|
|
1984
|
+
);
|
|
1985
|
+
const env = await getEnvironment();
|
|
1986
|
+
const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
1987
|
+
|
|
1988
|
+
const { items, total } = await env.getEntries({
|
|
1989
|
+
content_type: "topicProduct",
|
|
1990
|
+
"fields.catalogs.sys.id": catalog,
|
|
1991
|
+
limit,
|
|
1992
|
+
skip: offset,
|
|
1993
|
+
locale: defEnvLocaleCode,
|
|
1994
|
+
include: 0,
|
|
1995
|
+
select: "sys,fields",
|
|
1996
|
+
"sys.archivedAt[exists]": false,
|
|
1997
|
+
});
|
|
1998
|
+
|
|
1999
|
+
for (let item of items) {
|
|
2000
|
+
log(`Set audtodescription of the topic ${item.sys.id}`);
|
|
2001
|
+
const autoDescription = await getTopicProductAutodescription(item);
|
|
2002
|
+
item.fields.autoDescription = autoDescription;
|
|
2003
|
+
console.log(item.fields);
|
|
2004
|
+
if (!item.isArchived()) {
|
|
2005
|
+
item = await item.update();
|
|
2006
|
+
if (item.isPublished()) {
|
|
2007
|
+
item = await item.publish();
|
|
2008
|
+
}
|
|
2009
|
+
} else {
|
|
2010
|
+
log(
|
|
2011
|
+
`Product ${item.sys.id} is archived, it is not possible to update the autodescription`,
|
|
2012
|
+
"WARN"
|
|
2013
|
+
);
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
return {
|
|
2018
|
+
catalog,
|
|
2019
|
+
offset: Number(offset),
|
|
2020
|
+
limit: Number(limit),
|
|
2021
|
+
completed: false,
|
|
2022
|
+
total,
|
|
2023
|
+
};
|
|
2024
|
+
};
|