pim-import 4.3.0 → 4.4.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.
Files changed (56) hide show
  1. package/dist/algolia/downloads.js +2 -2
  2. package/dist/algolia/downloads.js.map +1 -1
  3. package/dist/algolia/families.js +2 -2
  4. package/dist/algolia/families.js.map +1 -1
  5. package/dist/algolia/models.js +5 -5
  6. package/dist/algolia/models.js.map +1 -1
  7. package/dist/algolia/news.js +3 -3
  8. package/dist/algolia/news.js.map +1 -1
  9. package/dist/algolia/pressRelease.js +3 -3
  10. package/dist/algolia/pressRelease.js.map +1 -1
  11. package/dist/algolia/pressReview.js +1 -1
  12. package/dist/algolia/pressReview.js.map +1 -1
  13. package/dist/algolia/products.js +20 -20
  14. package/dist/algolia/products.js.map +1 -1
  15. package/dist/algolia/projects.js +1 -1
  16. package/dist/algolia/projects.js.map +1 -1
  17. package/dist/algolia/stories.js +8 -10
  18. package/dist/algolia/stories.js.map +1 -1
  19. package/dist/algolia/subFamilies.js +5 -5
  20. package/dist/algolia/subFamilies.js.map +1 -1
  21. package/dist/algolia/subModels.js +6 -6
  22. package/dist/algolia/subModels.js.map +1 -1
  23. package/dist/index.js +2 -2
  24. package/dist/libs/contentful-cda.js +6 -11
  25. package/dist/libs/contentful-cda.js.map +1 -1
  26. package/dist/libs/contentful.js +13 -19
  27. package/dist/libs/contentful.js.map +1 -1
  28. package/dist/libs/imgix.js +3 -3
  29. package/dist/libs/imgix.js.map +1 -1
  30. package/dist/pim/methods/bulkPublish.js +37 -18
  31. package/dist/pim/methods/bulkPublish.js.map +1 -1
  32. package/dist/utils.js +11 -1
  33. package/dist/utils.js.map +1 -1
  34. package/package.json +1 -1
  35. package/src/algolia/downloads.ts +1 -3
  36. package/src/algolia/families.ts +2 -4
  37. package/src/algolia/models.ts +4 -7
  38. package/src/algolia/news.ts +10 -4
  39. package/src/algolia/pressRelease.ts +11 -4
  40. package/src/algolia/pressReview.ts +8 -2
  41. package/src/algolia/products.ts +9 -26
  42. package/src/algolia/projects.ts +6 -2
  43. package/src/algolia/stories.ts +21 -12
  44. package/src/algolia/subFamilies.ts +9 -9
  45. package/src/algolia/subModels.ts +10 -10
  46. package/src/index.ts +1 -1
  47. package/src/libs/contentful-cda.ts +17 -15
  48. package/src/libs/contentful.ts +15 -24
  49. package/src/libs/imgix.ts +6 -4
  50. package/src/pim/methods/bulkPublish.ts +38 -19
  51. package/src/utils.ts +22 -0
  52. package/types/index.d.ts +1 -1
  53. package/types/libs/contentful-cda.d.ts +1 -1
  54. package/types/libs/contentful.d.ts +1 -1
  55. package/types/pim/methods/bulkPublish.d.ts +5 -2
  56. package/types/utils.d.ts +1 -0
@@ -23,8 +23,8 @@ import {
23
23
  getLocalISOTime,
24
24
  secondBetweenTwoDate,
25
25
  capitalizeFirstLetter,
26
- keysToLowerCase,
27
26
  addProductFieldValueCodesByPimDetails,
27
+ getAllTranslations,
28
28
  } from "../utils";
29
29
  import productFieldsRequiredData from "../pim/data/productFields.json";
30
30
  import { getWrapperImgixFields } from "../libs/imgix";
@@ -154,8 +154,7 @@ const getObject = async (
154
154
  const catalogs = await getTopicDetails(
155
155
  topicSubModelWithFields,
156
156
  "catalog",
157
- "topicCatalog",
158
- true
157
+ "topicCatalog"
159
158
  );
160
159
  const catalog = catalogs?.[0];
161
160
  let productFields = [];
@@ -179,8 +178,7 @@ const getObject = async (
179
178
  const productLines = await getTopicDetails(
180
179
  topicSubModelWithFields,
181
180
  "productLine",
182
- "topicProductLine",
183
- true
181
+ "topicProductLine"
184
182
  );
185
183
  const productLine = productLines?.[0];
186
184
 
@@ -188,8 +186,7 @@ const getObject = async (
188
186
  const parentModels = await getTopicDetails(
189
187
  topicSubModelWithFields,
190
188
  "parentModel",
191
- "topicModel",
192
- true
189
+ "topicModel"
193
190
  );
194
191
  const parentModel = parentModels?.[0];
195
192
 
@@ -198,7 +195,6 @@ const getObject = async (
198
195
  topicSubModelWithFields,
199
196
  "subFamily",
200
197
  "topicSubFamily",
201
- true,
202
198
  false,
203
199
  true,
204
200
  true
@@ -219,11 +215,15 @@ const getObject = async (
219
215
 
220
216
  const record: AlgoliaSubModelRecord = {
221
217
  objectID: topicSubModelWithFields.sys.id,
222
- names: keysToLowerCase(topicSubModelWithFields?.fields?.name) || {},
218
+ names: await getAllTranslations(
219
+ topicSubModelWithFields?.fields?.name || {}
220
+ ),
223
221
  code:
224
222
  topicSubModelWithFields?.fields?.code?.[defaultEnvironmentLocaleCode] ||
225
223
  "",
226
- description: topicSubModelWithFields?.fields?.description || {},
224
+ description: await getAllTranslations(
225
+ topicSubModelWithFields?.fields?.description || {}
226
+ ),
227
227
  thumbnailImgix,
228
228
  catalog,
229
229
  productLine,
package/src/index.ts CHANGED
@@ -44,7 +44,7 @@ export {
44
44
  removeAllProductModelProductRelations,
45
45
  getProductPageIdByCode,
46
46
  } from "./pim/methods/products";
47
- export { publishAllDraftProducts } from "./pim/methods/bulkPublish";
47
+ export { publishAllProductDrafts } from "./pim/methods/bulkPublish";
48
48
  // export {
49
49
  // createOrUpdateCatalogPages,
50
50
  // createOrUpdateCatalogPageByCode,
@@ -6,7 +6,11 @@ import {
6
6
  AssetPropFieldsWithoutLocaleKey,
7
7
  OtherFilters,
8
8
  } from "../types";
9
- import { getPimTranslations, keysToLowerCase } from "../utils";
9
+ import {
10
+ getPimTranslations,
11
+ keysToLowerCase,
12
+ getAllTranslations,
13
+ } from "../utils";
10
14
  import { log } from "./logs";
11
15
  const contentful = require("contentful");
12
16
 
@@ -255,16 +259,15 @@ export const getEntryImageDetails = async (entry: Entry, fieldKey: string) => {
255
259
  * @param topicEntry
256
260
  * @param fieldKey
257
261
  * @param contentType
258
- * @param lowerCaseKeys Default false
259
262
  * @param showRelatedEntities Default false
260
263
  * @param isCatalogEntry Default true
264
+ * @param skipPageSlugs Default false
261
265
  * @returns
262
266
  */
263
267
  export const getTopicDetails = async (
264
268
  topicEntry: Entry,
265
269
  fieldKey: string,
266
270
  contentType: string,
267
- lowerCaseKeys: boolean = false,
268
271
  showRelatedEntities: boolean = false,
269
272
  isCatalogEntry: boolean = true,
270
273
  skipPageSlugs: boolean = false
@@ -302,10 +305,7 @@ export const getTopicDetails = async (
302
305
  if (entries) {
303
306
  for (const entry of entries) {
304
307
  const data: TopicDetailsResponse = {
305
- names:
306
- entry?.fields?.name && lowerCaseKeys
307
- ? keysToLowerCase(entry.fields.name)
308
- : {},
308
+ names: await getAllTranslations(entry?.fields?.name || {}),
309
309
  code: entry?.fields?.code?.[defEnvLocaleCode],
310
310
  };
311
311
  if (!skipPageSlugs) {
@@ -316,10 +316,7 @@ export const getTopicDetails = async (
316
316
  } else {
317
317
  entryPage = await getTopicPage(entry.sys.id);
318
318
  }
319
- data.slugs =
320
- entryPage?.fields?.slug && lowerCaseKeys
321
- ? keysToLowerCase(entryPage.fields.slug)
322
- : {};
319
+ data.slugs = await getAllTranslations(entryPage?.fields?.slug || {});
323
320
  }
324
321
 
325
322
  if (contentType === "topicSubFamily" && showRelatedEntities) {
@@ -377,10 +374,15 @@ export const getSubFamilySlugDetails = async (topicSubFamily: Entry) => {
377
374
  : {};
378
375
 
379
376
  return {
380
- catalogPageSlugs: keysToLowerCase(subFamilyCatalogPage?.fields?.slug) || {},
381
- familyPageSlugs: keysToLowerCase(subFamilyFamilyPage?.fields?.slug) || {},
382
- categoryPageSlugs:
383
- keysToLowerCase(subFamilyCategoryPage?.fields?.slug) || {},
377
+ catalogPageSlugs: await getAllTranslations(
378
+ subFamilyCatalogPage?.fields?.slug || {}
379
+ ),
380
+ familyPageSlugs: await getAllTranslations(
381
+ subFamilyFamilyPage?.fields?.slug || {}
382
+ ),
383
+ categoryPageSlugs: await getAllTranslations(
384
+ subFamilyCategoryPage?.fields?.slug || {}
385
+ ),
384
386
  };
385
387
  };
386
388
 
@@ -31,6 +31,7 @@ import {
31
31
  getPimTranslations,
32
32
  keysToLowerCase,
33
33
  replaceAll,
34
+ getAllTranslations,
34
35
  } from "../utils";
35
36
  import { getSubFamilySlugDetails } from "../pim/methods/subfamilies";
36
37
  import { removeProductObject } from "../algolia/products";
@@ -1094,18 +1095,18 @@ export const addFieldValue = async (
1094
1095
  * @param topicEntry
1095
1096
  * @param fieldKey
1096
1097
  * @param contentType
1097
- * @param lowerCaseKeys Default false
1098
1098
  * @param showRelatedEntities Default false
1099
1099
  * @param isCatalogEntry Default true
1100
+ * @param skipPageSlugs Default false
1100
1101
  * @returns
1101
1102
  */
1102
1103
  export const getTopicDetails = async (
1103
1104
  topicEntry: Entry,
1104
1105
  fieldKey: string,
1105
1106
  contentType: string,
1106
- lowerCaseKeys: boolean = false,
1107
1107
  showRelatedEntities: boolean = false,
1108
- isCatalogEntry: boolean = true
1108
+ isCatalogEntry: boolean = true,
1109
+ skipPageSlugs: boolean = false
1109
1110
  ): Promise<TopicDetailsResponse[]> => {
1110
1111
  const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
1111
1112
  const isHasToManyField = Array.isArray(
@@ -1138,36 +1139,26 @@ export const getTopicDetails = async (
1138
1139
  );
1139
1140
 
1140
1141
  if (entries) {
1141
- let count = 0;
1142
1142
  for (const entry of entries) {
1143
- let entryPage: any = {};
1144
- if (isCatalogEntry) {
1145
- const entryPageId = `${entry.sys.id}_PAGE`;
1146
- entryPage = await getEntryByID(entryPageId, "page", "fields.slug");
1147
- } else {
1148
- entryPage = await getTopicPage(entry.sys.id);
1149
- }
1150
-
1151
1143
  const data: TopicDetailsResponse = {
1152
- names:
1153
- entry?.fields?.name && lowerCaseKeys
1154
- ? keysToLowerCase(entry.fields.name)
1155
- : {},
1144
+ names: await getAllTranslations(entry?.fields?.name || {}),
1156
1145
  code: entry?.fields?.code?.[defEnvLocaleCode],
1157
- slugs:
1158
- entryPage?.fields?.slug && lowerCaseKeys
1159
- ? keysToLowerCase(entryPage.fields.slug)
1160
- : {},
1161
1146
  };
1147
+ if (!skipPageSlugs) {
1148
+ let entryPage: any = {};
1149
+ if (isCatalogEntry) {
1150
+ const entryPageId = `${entry.sys.id}_PAGE`;
1151
+ entryPage = await getEntryByID(entryPageId, "page", "fields.slug");
1152
+ } else {
1153
+ entryPage = await getTopicPage(entry.sys.id);
1154
+ }
1155
+ data.slugs = await getAllTranslations(entryPage?.fields?.slug || {});
1156
+ }
1162
1157
 
1163
1158
  if (contentType === "topicSubFamily" && showRelatedEntities) {
1164
1159
  data.details = await getSubFamilySlugDetails(entry);
1165
1160
  }
1166
1161
 
1167
- if (++count > 0 && count % 7 === 0) {
1168
- await sleep(2000, true);
1169
- }
1170
-
1171
1162
  items.push(data);
1172
1163
  }
1173
1164
  }
package/src/libs/imgix.ts CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  import axios from "@atoms-studio/axios";
10
10
  import https from "https";
11
11
  import mime from "mime-types";
12
- import { basename } from "../utils";
12
+ import { basename, getAllTranslations } from "../utils";
13
13
 
14
14
  let imgix: ImgixAPI;
15
15
  export const getImgix = () => {
@@ -204,9 +204,11 @@ export const getWrapperImgixFields = async (wrapperImgixId: string) => {
204
204
  focalPoint:
205
205
  wrapperImgix?.fields?.focalPoint?.[defaultEnvironmentLocaleCode]
206
206
  ?.focalPoint || {},
207
- altText: wrapperImgix?.fields?.altText || {},
208
- caption: wrapperImgix?.fields?.caption || {},
209
- hoverTitle: wrapperImgix?.fields?.hoverTitle || {},
207
+ altText: await getAllTranslations(wrapperImgix?.fields?.altText || {}),
208
+ caption: await getAllTranslations(wrapperImgix?.fields?.caption || {}),
209
+ hoverTitle: await getAllTranslations(
210
+ wrapperImgix?.fields?.hoverTitle || {}
211
+ ),
210
212
  forceHoverTitle:
211
213
  !!wrapperImgix?.fields?.forceHoverTitle?.[defaultEnvironmentLocaleCode],
212
214
  };
@@ -5,7 +5,7 @@ import {
5
5
  getEntryByID,
6
6
  getEnvironment,
7
7
  } from "../../libs/contentful";
8
- import { log } from "../../libs/logs";
8
+ import { log, serverUtils } from "../../libs/logs";
9
9
  import { getProductPageIdByCode } from "./products";
10
10
  import { reindexProduct } from "../../algolia/products";
11
11
 
@@ -194,21 +194,22 @@ export const publishTopicProduct = async (productEntry: Entry) => {
194
194
  await productEntry.publish();
195
195
  };
196
196
 
197
- export const publishAllDraftProducts = async (
197
+ export const publishAllProductDrafts = async (
198
198
  filters: { catalog?: AvailableCatalogs; family?: string },
199
- skip: number = 0,
200
199
  limit: number = 100
201
200
  ) => {
202
- log(
203
- `publishAllDraftProductsByCatalog catalog: ${filters?.catalog} family: ${filters?.family} skip: ${skip} limit: ${limit}`
204
- );
201
+ let logMsg = `publishAllProductDrafts catalog: ${filters?.catalog} family: ${filters?.family} limit: ${limit}`;
202
+ log(logMsg);
203
+ if (serverUtils) {
204
+ serverUtils.log(logMsg);
205
+ }
205
206
  const env = await getEnvironment();
206
207
  const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
207
208
 
208
209
  const opts: any = {
209
210
  content_type: "topicProduct",
210
211
  limit,
211
- skip,
212
+ skip: 0,
212
213
  locale: defEnvLocaleCode,
213
214
  "sys.archivedAt[exists]": false,
214
215
  "sys.publishedAt[exists]": false,
@@ -222,26 +223,44 @@ export const publishAllDraftProducts = async (
222
223
  }
223
224
  const { items, total } = await env.getEntries(opts);
224
225
 
225
- let count = skip;
226
+ let count = 0;
226
227
  for (const item of items) {
227
- log(`${++count} of ${limit} - total: ${total}`);
228
+ logMsg = `${++count} of ${limit} - total: ${total}`;
229
+ log(logMsg);
230
+ if (serverUtils) {
231
+ serverUtils.log(logMsg);
232
+ }
228
233
  if (["0000000-TEST"].includes(item.sys.id)) {
229
- log(`Skip product test ${item.sys.id}`);
234
+ logMsg = `Skip product test ${item.sys.id}`;
230
235
  } else {
231
236
  try {
232
- log(`Publishing product: ${item.sys.id}`);
237
+ logMsg = `Publishing product: ${item.sys.id}`;
238
+ if (serverUtils) {
239
+ serverUtils.log(logMsg);
240
+ }
233
241
  await publishTopicProduct(item);
234
- log(`Reindex product: ${item.sys.id}`);
242
+ logMsg = `Reindex product: ${item.sys.id}`;
243
+ if (serverUtils) {
244
+ serverUtils.log(logMsg);
245
+ }
235
246
  await reindexProduct(item.sys.id, true);
247
+
248
+ if (serverUtils) {
249
+ const progress = Math.floor((count / items.length) * 100);
250
+ serverUtils.updateProgress(progress);
251
+ }
236
252
  } catch (err) {
237
- log(`Publish entry ${item.sys.id} failed`);
253
+ logMsg = `Publish entry ${item.sys.id} failed`;
254
+ if (serverUtils) {
255
+ serverUtils.log(logMsg);
256
+ }
238
257
  }
239
258
  }
240
259
  }
241
- const completed = Number(skip) + Number(limit) >= total;
242
- if (!completed) {
243
- publishAllDraftProducts(filters, 0, limit);
244
- } else {
245
- log("Completed!");
246
- }
260
+
261
+ const completed = Number(limit) >= total;
262
+ return {
263
+ completed,
264
+ total,
265
+ };
247
266
  };
package/src/utils.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  } from "./types";
9
9
  import { AssetsEntity } from "./resources/ProductDetails";
10
10
  import { log } from "./libs/logs";
11
+ import { cfLocales, getEnvironmentDefaultLocaleCode } from "./libs/contentful";
11
12
 
12
13
  /**
13
14
  * Merge two objects
@@ -326,3 +327,24 @@ export const replaceAll = (original: string, from: string, to: string) => {
326
327
  const regExp = new RegExp(from, "g");
327
328
  return original.replace(regExp, to);
328
329
  };
330
+
331
+ /**
332
+ * Get all locale translations
333
+ *
334
+ *
335
+ * @param {object} values
336
+ *
337
+ * @example getAllTranslations({en:foo}) => {en:foo, it: foo, de: foo...}
338
+ *
339
+ * @returns
340
+ */
341
+ export const getAllTranslations = async (values: any) => {
342
+ const defaultLocale = await getEnvironmentDefaultLocaleCode();
343
+
344
+ const newValue: any = {};
345
+ for (const locale of cfLocales) {
346
+ newValue[locale] = values?.[locale] || values[defaultLocale] || "";
347
+ }
348
+
349
+ return keysToLowerCase(newValue);
350
+ };
package/types/index.d.ts CHANGED
@@ -9,7 +9,7 @@ export { importSubModels } from "./pim/methods/submodels";
9
9
  export { importSubFamilies } from "./pim/methods/subfamilies";
10
10
  export { importFamilies } from "./pim/methods/families";
11
11
  export { importProductByCode, setProductsRelationships, setProductRelationships, getAllProductEntriesByCatalog, audit, generateTechSpecPdf, setProductsAutodescription, getProductAutodescription, setProductAutodescriptionByTopicId, removeProductFromColorVariantsByProductLine, removeAllProductModelProductRelations, getProductPageIdByCode, } from "./pim/methods/products";
12
- export { publishAllDraftProducts } from "./pim/methods/bulkPublish";
12
+ export { publishAllProductDrafts } from "./pim/methods/bulkPublish";
13
13
  export { resetIndexSettings } from "./algolia/config";
14
14
  export { reindexFamilies, reindexFamily, removeFamilyObject, } from "./algolia/families";
15
15
  export { reindexSubFamilies, reindexSubFamily, removeSubFamilyObject, } from "./algolia/subFamilies";
@@ -8,7 +8,7 @@ export declare const getEntryByID: (entryID: string, contentTypeId: string, sele
8
8
  export declare const getAllEntries: (contentType: string, select?: string | undefined, filterKey?: string | undefined, filterValue?: string | undefined, limit?: number, otherFilters?: OtherFilters[] | undefined, include?: number) => Promise<Entry[]>;
9
9
  export declare const getAssetDetails: (assetId: string) => Promise<AssetPropFieldsWithoutLocaleKey>;
10
10
  export declare const getEntryImageDetails: (entry: Entry, fieldKey: string) => Promise<string>;
11
- export declare const getTopicDetails: (topicEntry: Entry, fieldKey: string, contentType: string, lowerCaseKeys?: boolean, showRelatedEntities?: boolean, isCatalogEntry?: boolean, skipPageSlugs?: boolean) => Promise<TopicDetailsResponse[]>;
11
+ export declare const getTopicDetails: (topicEntry: Entry, fieldKey: string, contentType: string, showRelatedEntities?: boolean, isCatalogEntry?: boolean, skipPageSlugs?: boolean) => Promise<TopicDetailsResponse[]>;
12
12
  export declare const getSubFamilySlugDetails: (topicSubFamily: Entry) => Promise<{
13
13
  catalogPageSlugs: any;
14
14
  familyPageSlugs: any;
@@ -47,7 +47,7 @@ export declare const deleteEntries: (contentType: string, catalogCode?: Availabl
47
47
  export declare const addToRelationFields: (entry: Entry | any, fieldKey: string, entrySysIdValue: string, manyReferences?: boolean, resetOldValues?: boolean, linkType?: "Asset" | "Entry") => Promise<Entry>;
48
48
  export declare const removeFromRelationFields: (entry: Entry | any, fieldKey: string, entrySysIdValue: string, manyReferences?: boolean) => Promise<any>;
49
49
  export declare const addFieldValue: (entry: Entry | any, fieldKey: string, fieldValue: any, manyReferences?: boolean) => Promise<any>;
50
- export declare const getTopicDetails: (topicEntry: Entry, fieldKey: string, contentType: string, lowerCaseKeys?: boolean, showRelatedEntities?: boolean, isCatalogEntry?: boolean) => Promise<TopicDetailsResponse[]>;
50
+ export declare const getTopicDetails: (topicEntry: Entry, fieldKey: string, contentType: string, showRelatedEntities?: boolean, isCatalogEntry?: boolean, skipPageSlugs?: boolean) => Promise<TopicDetailsResponse[]>;
51
51
  export declare const getAssetDetails: (assetId: string) => Promise<AssetPropFields>;
52
52
  export declare const getEntryImageDetails: (entry: Entry, fieldKey: string) => Promise<string>;
53
53
  export declare const getDictionaryJson: () => Promise<any>;
@@ -1,7 +1,10 @@
1
1
  import { AvailableCatalogs } from "../../types";
2
2
  import type { Entry } from "contentful-management/dist/typings/entities/entry";
3
3
  export declare const publishTopicProduct: (productEntry: Entry) => Promise<void>;
4
- export declare const publishAllDraftProducts: (filters: {
4
+ export declare const publishAllProductDrafts: (filters: {
5
5
  catalog?: AvailableCatalogs;
6
6
  family?: string;
7
- }, skip?: number, limit?: number) => Promise<void>;
7
+ }, limit?: number) => Promise<{
8
+ completed: boolean;
9
+ total: number;
10
+ }>;
package/types/utils.d.ts CHANGED
@@ -17,3 +17,4 @@ export declare const capitalizeFirstLetter: (text: string) => string;
17
17
  export declare const keysToLowerCase: (obj: any, includeNestedKeys?: boolean) => any;
18
18
  export declare const addProductFieldValueCodesByPimDetails: (pimDetails: any, productFields: any, fieldKey: string, fieldParentKey?: string | undefined) => string[];
19
19
  export declare const replaceAll: (original: string, from: string, to: string) => string;
20
+ export declare const getAllTranslations: (values: any) => Promise<any>;