pim-import 5.8.0 → 5.9.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.
@@ -80,7 +80,6 @@ const getProductFields = async (topicFamily, destination = "PROFESSIONAL_GLOBAL"
80
80
  let productFields = {};
81
81
  productFields.availableTo = [];
82
82
  productFields.totalProducts = topicProductEntries.length;
83
- productFields.certificationFilters = [];
84
83
  productFields.certifiedFilters = [];
85
84
  for (const topicProduct of topicProductEntries) {
86
85
  if (topicProduct?.fields?.productFields?.[defaultEnvironmentLocaleCode]) {
@@ -125,13 +124,6 @@ const getProductFields = async (topicFamily, destination = "PROFESSIONAL_GLOBAL"
125
124
  productFields = (0, utils_1.addProductFieldValueCodesByPimDetails)(pimDetails, productFields, "shapes", "physical");
126
125
  productFields = (0, utils_1.addProductFieldValueCodesByPimDetails)(pimDetails, productFields, "certifications");
127
126
  productFields = (0, utils_1.addProductFieldValueCodesByPimDetails)(pimDetails, productFields, "locations");
128
- (0, logs_1.log)(`Get certificationFilters details...`);
129
- productFields.certificationFilters = [
130
- ...new Set([
131
- ...productFields.certificationFilters,
132
- ...(0, utils_1.getCertificationFilters)(pimDetails),
133
- ]),
134
- ];
135
127
  (0, logs_1.log)(`Get certifiedFilters details...`);
136
128
  productFields.certifiedFilters = [
137
129
  ...new Set([
@@ -139,16 +131,6 @@ const getProductFields = async (topicFamily, destination = "PROFESSIONAL_GLOBAL"
139
131
  ...(0, utils_1.getCertifiedFilters)(pimDetails),
140
132
  ]),
141
133
  ];
142
- (0, logs_1.log)(`Get filterableCertifications details...`);
143
- const filterableCertificationsFields = ["enec", "ul", "certificates"];
144
- for (const filterableCertificationsField of filterableCertificationsFields) {
145
- productFields = (0, utils_1.addProductFieldValueCodesByPimDetails)(pimDetails, productFields, filterableCertificationsField, "certification", "filterableCertifications", false);
146
- }
147
- if (!productFields?.filterableCertifications) {
148
- productFields.filterableCertifications = {};
149
- }
150
- productFields.filterableCertifications.enecCertified =
151
- !!pimDetails.certification?.enecCertified;
152
134
  productFields = (0, utils_1.addProductFieldValueCodesByPimDetails)(pimDetails, productFields, "destinations");
153
135
  }
154
136
  }
@@ -74,7 +74,6 @@ const getObject = async (topicModel) => {
74
74
  productFields.availableTo = [];
75
75
  if (catalogId) {
76
76
  const topicProducts = await (0, contentful_cda_1.getAllEntries)("topicProduct", "sys,fields.productFields", `fields.models${(0, utils_1.capitalizeFirstLetter)(catalogId)}.sys.id[in]`, topicModelWithFields.sys.id);
77
- productFields.certificationFilters = [];
78
77
  productFields.certifiedFilters = [];
79
78
  topicProducts.forEach((topicProduct) => {
80
79
  const pimDetails = topicProduct?.fields?.productFields?.[defaultEnvironmentLocaleCode];
@@ -106,12 +105,6 @@ const getObject = async (topicModel) => {
106
105
  productFields = (0, utils_1.addProductFieldValueCodesByPimDetails)(pimDetails, productFields, "cri", "photometric");
107
106
  productFields = (0, utils_1.addProductFieldValueCodesByPimDetails)(pimDetails, productFields, "powerSupplyType", "electrical");
108
107
  productFields = (0, utils_1.addProductFieldValueCodesByPimDetails)(pimDetails, productFields, "ipRating", "marking");
109
- productFields.certificationFilters = [
110
- ...new Set([
111
- ...productFields.certificationFilters,
112
- ...(0, utils_1.getCertificationFilters)(pimDetails),
113
- ]),
114
- ];
115
108
  productFields.certifiedFilters = [
116
109
  ...new Set([
117
110
  ...productFields.certifiedFilters,
@@ -24,7 +24,11 @@ const triggerPDFGenerator = async (topicProductId, multipleDestinations = false)
24
24
  let destinationsData = [];
25
25
  if (multipleDestinations) {
26
26
  destinationsData = topicProduct.fields.destinations[defaultEnvironmentLocaleCode]
27
- .filter((destination) => ["PROFESSIONAL_GLOBAL", "PROFESSIONAL_US"].includes(destination))
27
+ .filter((destination) => [
28
+ "PROFESSIONAL_GLOBAL",
29
+ "PROFESSIONAL_US",
30
+ "PROFESSIONAL_CHINA",
31
+ ].includes(destination))
28
32
  .map((destination) => {
29
33
  switch (destination) {
30
34
  case "PROFESSIONAL_US":
@@ -32,6 +36,11 @@ const triggerPDFGenerator = async (topicProductId, multipleDestinations = false)
32
36
  locale: "en-US",
33
37
  country: "us",
34
38
  };
39
+ case "PROFESSIONAL_CHINA":
40
+ return {
41
+ locale: "zh",
42
+ country: "cn",
43
+ };
35
44
  default:
36
45
  return defaultData;
37
46
  }
@@ -171,15 +180,8 @@ const getObject = async (topicProduct) => {
171
180
  if (productFields.marking?.markings?.length) {
172
181
  productFields.certificationIcons = productFields.certificationIcons.concat(productFields.marking.markings);
173
182
  }
174
- (0, logs_1.log)(`Get certificationFilters details...`);
175
- productFields.certificationFilters = (0, utils_1.getCertificationFilters)(topicProductWithFields?.fields?.productFields?.[defaultEnvironmentLocaleCode]);
176
183
  (0, logs_1.log)(`Get certifiedFilters details...`);
177
184
  productFields.certifiedFilters = (0, utils_1.getCertifiedFilters)(topicProductWithFields?.fields?.productFields?.[defaultEnvironmentLocaleCode]);
178
- (0, logs_1.log)(`Get filterableCertifications details...`);
179
- const filterableCertificationsFields = ["enec", "ul", "certificates"];
180
- for (const filterableCertificationsField of filterableCertificationsFields) {
181
- productFields = (0, utils_1.addProductFieldValueCodesByPimDetails)(topicProductWithFields.fields.productFields?.[defaultEnvironmentLocaleCode], productFields, filterableCertificationsField, "certification", "filterableCertifications", false, true);
182
- }
183
185
  if (!productFields?.certification) {
184
186
  productFields.certification = {};
185
187
  }
@@ -76,7 +76,6 @@ const getProductFields = async (topicSubFamily, destination = "PROFESSIONAL_GLOB
76
76
  for (const destination of allDestinations) {
77
77
  productFields.totalProducts[destination] = topicProductEntries.filter((topicProductEntry) => topicProductEntry?.fields?.productFields?.[defaultEnvironmentLocaleCode]?.destinations?.find((productDestination) => productDestination.code === destination)).length;
78
78
  }
79
- productFields.certificationFilters = [];
80
79
  productFields.certifiedFilters = [];
81
80
  for (const topicProduct of topicProductEntries) {
82
81
  if (topicProduct?.fields?.productFields?.[defaultEnvironmentLocaleCode]) {
@@ -124,22 +123,12 @@ const getProductFields = async (topicSubFamily, destination = "PROFESSIONAL_GLOB
124
123
  productFields = (0, utils_1.addProductFieldValueCodesByPimDetails)(pimDetails, productFields, "ipCategory", "marking");
125
124
  productFields = (0, utils_1.addProductFieldValueCodesByPimDetails)(pimDetails, productFields, "ipRating", "marking");
126
125
  productFields = (0, utils_1.addProductFieldValueCodesByPimDetails)(pimDetails, productFields, "markings", "marking");
127
- productFields.certificationFilters = [
128
- ...new Set([
129
- ...productFields.certificationFilters,
130
- ...(0, utils_1.getCertificationFilters)(pimDetails),
131
- ]),
132
- ];
133
126
  productFields.certifiedFilters = [
134
127
  ...new Set([
135
128
  ...productFields.certifiedFilters,
136
129
  ...(0, utils_1.getCertifiedFilters)(pimDetails),
137
130
  ]),
138
131
  ];
139
- const filterableCertificationsFields = ["enec", "ul", "certificates"];
140
- for (const filterableCertificationsField of filterableCertificationsFields) {
141
- productFields = (0, utils_1.addProductFieldValueCodesByPimDetails)(pimDetails, productFields, filterableCertificationsField, "certification", "filterableCertifications", false, true);
142
- }
143
132
  if (!productFields?.certification) {
144
133
  productFields.certification = {};
145
134
  }
@@ -3,7 +3,7 @@ import type { Entry } from "contentful-management/dist/typings/entities/entry";
3
3
  export declare const publishTopicProduct: (productEntry: Entry) => Promise<void>;
4
4
  export declare const publishAllProductDrafts: (filters: {
5
5
  catalog?: AvailableCatalogs;
6
- family?: string;
6
+ destination?: string;
7
7
  }, limit?: number) => Promise<{
8
8
  completed: boolean;
9
9
  total: number;
@@ -22,7 +22,7 @@ const publishTopicProduct = async (productEntry) => {
22
22
  };
23
23
  exports.publishTopicProduct = publishTopicProduct;
24
24
  const publishAllProductDrafts = async (filters, limit = 100) => {
25
- let logMsg = `publishAllProductDrafts catalog: ${filters?.catalog} family: ${filters?.family} limit: ${limit}`;
25
+ let logMsg = `publishAllProductDrafts limit: ${limit} filters: ${JSON.stringify(filters)}`;
26
26
  (0, logs_1.log)(logMsg);
27
27
  if (logs_1.serverUtils) {
28
28
  logs_1.serverUtils.log(logMsg);
@@ -41,8 +41,8 @@ const publishAllProductDrafts = async (filters, limit = 100) => {
41
41
  if (filters?.catalog) {
42
42
  opts["fields.catalogs.sys.id"] = filters.catalog;
43
43
  }
44
- if (filters?.family) {
45
- opts["fields.families.sys.id"] = filters.family;
44
+ if (filters?.destination) {
45
+ opts["fields.destinations[in]"] = filters.destination;
46
46
  }
47
47
  const { items, total } = await env.getEntries(opts);
48
48
  let count = 0;
@@ -52,6 +52,9 @@ const publishAllProductDrafts = async (filters, limit = 100) => {
52
52
  if (logs_1.serverUtils) {
53
53
  logs_1.serverUtils.log(logMsg);
54
54
  }
55
+ if (item.fields.destinations[defEnvLocaleCode]?.length > 1) {
56
+ console.log(item.sys.id, item.fields.destinations[defEnvLocaleCode]);
57
+ }
55
58
  if (["0000000-TEST"].includes(item.sys.id)) {
56
59
  logMsg = `Skip product test ${item.sys.id}`;
57
60
  }
@@ -1509,16 +1509,22 @@ const generateTechSpecPdf = async (topicProductId, country = "global", locale =
1509
1509
  const fileName = (pageSlug.length >= 170
1510
1510
  ? `tech-spec-${topicProductId}`
1511
1511
  : `tech-spec-${pageSlug}`) + `_${country}-${locale}`;
1512
- let baseUrl = process.env.FPI_TECH_SPEC_BASE_URL ?? "";
1512
+ let baseUrl = country === "cn"
1513
+ ? process.env.FPI_TECH_SPEC_BASE_URL_CN ?? ""
1514
+ : process.env.FPI_TECH_SPEC_BASE_URL ?? "";
1513
1515
  if (!baseUrl) {
1514
- (0, logs_1.log)(`FPI_TECH_SPEC_BASE_URL process env not found`, "ERROR");
1516
+ (0, logs_1.log)(`FPI_TECH_SPEC_BASE_URL process env not found for country ${country}`, "ERROR");
1515
1517
  }
1516
1518
  baseUrl = baseUrl.replace(/\/?(\?|#|$)/, "/$1");
1517
- let footerBaseUrl = process.env.FPI_TECH_SPEC_FOOTER_BASE_URL ??
1518
- process.env.FPI_TECH_SPEC_BASE_URL ??
1519
- "";
1519
+ let footerBaseUrl = country === "cn"
1520
+ ? process.env.FPI_TECH_SPEC_FOOTER_BASE_URL_CN ??
1521
+ process.env.FPI_TECH_SPEC_BASE_URL_CN ??
1522
+ ""
1523
+ : process.env.FPI_TECH_SPEC_FOOTER_BASE_URL ??
1524
+ process.env.FPI_TECH_SPEC_BASE_URL ??
1525
+ "";
1520
1526
  if (!footerBaseUrl) {
1521
- (0, logs_1.log)(`FPI_TECH_SPEC_FOOTER_BASE_URL process env not found`, "ERROR");
1527
+ (0, logs_1.log)(`FPI_TECH_SPEC_FOOTER_BASE_URL process env not found for country ${country}`, "ERROR");
1522
1528
  }
1523
1529
  footerBaseUrl = footerBaseUrl.replace(/\/?(\?|#|$)/, "/$1");
1524
1530
  const layoutUrl = `${baseUrl}${locale}/${country}/tech-spec/${pageSlug}/v-${version}/`;
package/dist/utils.d.ts CHANGED
@@ -19,5 +19,4 @@ export declare const addProductFieldValueCodesByPimDetails: (pimDetails: any, pr
19
19
  export declare const replaceAll: (original: string, from: string, to: string) => string;
20
20
  export declare const getAllTranslations: (values: any) => Promise<any>;
21
21
  export declare const truncateString: (string: string, limit: number) => string;
22
- export declare const getCertificationFilters: (productFields: any) => any;
23
22
  export declare const getCertifiedFilters: (productFields: any) => any[];
package/dist/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCertifiedFilters = exports.getCertificationFilters = exports.truncateString = exports.getAllTranslations = exports.replaceAll = exports.addProductFieldValueCodesByPimDetails = exports.keysToLowerCase = exports.capitalizeFirstLetter = exports.getLocalISOTime = exports.doChunk = exports.sanitizeValue = exports.getUnwantedValues = exports.getPimTranslations = exports.getLocale = exports.pimLocaleMap = exports.stringToSlug = exports.secondBetweenTwoDate = exports.basename = exports.getBaseURL = exports.sleep = exports.mergeObjects = void 0;
3
+ exports.getCertifiedFilters = exports.truncateString = exports.getAllTranslations = exports.replaceAll = exports.addProductFieldValueCodesByPimDetails = exports.keysToLowerCase = exports.capitalizeFirstLetter = exports.getLocalISOTime = exports.doChunk = exports.sanitizeValue = exports.getUnwantedValues = exports.getPimTranslations = exports.getLocale = exports.pimLocaleMap = exports.stringToSlug = exports.secondBetweenTwoDate = exports.basename = exports.getBaseURL = exports.sleep = exports.mergeObjects = void 0;
4
4
  const logs_1 = require("./libs/logs");
5
5
  const contentful_1 = require("./libs/contentful");
6
6
  const mergeObjects = (objA, objB) => {
@@ -291,40 +291,6 @@ const truncateString = (string, limit) => {
291
291
  : string.slice(0, limit - separator.length) + "...";
292
292
  };
293
293
  exports.truncateString = truncateString;
294
- const getCertificationFilters = (productFields) => {
295
- let certificationFilters = [];
296
- certificationFilters =
297
- productFields?.certification?.certificates?.map((c) => c.code) || [];
298
- const availableCertificationCodes = [
299
- "CM1",
300
- "CM2",
301
- "CM3",
302
- "CM4",
303
- "CM5",
304
- "CM6",
305
- "CM7",
306
- "CM8",
307
- "CM9",
308
- "CM10",
309
- "CM11",
310
- "CM12",
311
- "CM13",
312
- "CM14",
313
- "CM15",
314
- "CM16",
315
- "CM17",
316
- "CM18",
317
- ];
318
- certificationFilters = certificationFilters?.filter((code) => availableCertificationCodes.includes(code));
319
- if (productFields?.certification?.enecCertified?.state === true)
320
- certificationFilters.push(productFields.certification.enecCertified.label?.value_en ||
321
- productFields.certification.enecCertified.label);
322
- if (productFields?.certification?.ulCertified?.state === true)
323
- certificationFilters.push(productFields.certification.ulCertified.label?.value_en ||
324
- productFields.certification.ulCertified.label);
325
- return certificationFilters;
326
- };
327
- exports.getCertificationFilters = getCertificationFilters;
328
294
  const getCertifiedFilters = (productFields) => {
329
295
  return productFields?.certified
330
296
  ? Object.values(productFields?.certified)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pim-import",
3
- "version": "5.8.0",
3
+ "version": "5.9.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",