pim-import 2.60.1 → 2.63.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 (43) hide show
  1. package/dist/algolia/config.js +18 -0
  2. package/dist/algolia/config.js.map +1 -1
  3. package/dist/algolia/downloads.js +6 -3
  4. package/dist/algolia/downloads.js.map +1 -1
  5. package/dist/algolia/families.js +8 -3
  6. package/dist/algolia/families.js.map +1 -1
  7. package/dist/algolia/models.js +8 -6
  8. package/dist/algolia/models.js.map +1 -1
  9. package/dist/algolia/news.js +142 -0
  10. package/dist/algolia/news.js.map +1 -0
  11. package/dist/algolia/pressRelease.js +6 -4
  12. package/dist/algolia/pressRelease.js.map +1 -1
  13. package/dist/algolia/pressReview.js +6 -4
  14. package/dist/algolia/pressReview.js.map +1 -1
  15. package/dist/algolia/products.js +8 -3
  16. package/dist/algolia/products.js.map +1 -1
  17. package/dist/algolia/projects.js +6 -4
  18. package/dist/algolia/projects.js.map +1 -1
  19. package/dist/algolia/stories.js +6 -4
  20. package/dist/algolia/stories.js.map +1 -1
  21. package/dist/algolia/subFamilies.js +8 -3
  22. package/dist/algolia/subFamilies.js.map +1 -1
  23. package/dist/algolia/subModels.js +3 -3
  24. package/dist/algolia/subModels.js.map +1 -1
  25. package/dist/index.js +7 -2
  26. package/dist/index.js.map +1 -1
  27. package/dist/pim/methods/products.js +38 -1
  28. package/dist/pim/methods/products.js.map +1 -1
  29. package/package.json +1 -1
  30. package/src/algolia/config.ts +20 -1
  31. package/src/algolia/downloads.ts +9 -3
  32. package/src/algolia/families.ts +14 -3
  33. package/src/algolia/models.ts +12 -7
  34. package/src/algolia/news.ts +233 -0
  35. package/src/algolia/pressRelease.ts +10 -4
  36. package/src/algolia/pressReview.ts +10 -4
  37. package/src/algolia/products.ts +14 -3
  38. package/src/algolia/projects.ts +10 -4
  39. package/src/algolia/stories.ts +10 -4
  40. package/src/algolia/subFamilies.ts +14 -3
  41. package/src/algolia/subModels.ts +4 -4
  42. package/src/index.ts +2 -0
  43. package/src/pim/methods/products.ts +56 -0
@@ -31,6 +31,13 @@ export type AlgoliaPressReleaseRecord = {
31
31
  visualizationDate?: string;
32
32
  };
33
33
 
34
+ const isObjectToDelete = (
35
+ object: any,
36
+ defaultEnvironmentLocaleCode: string
37
+ ) => {
38
+ return !object?.name?.[defaultEnvironmentLocaleCode];
39
+ };
40
+
34
41
  const getObject = async (
35
42
  topicPressRelease: Entry
36
43
  ): Promise<AlgoliaPressReleaseRecord> => {
@@ -129,8 +136,7 @@ export const reindexPressRelease = async (topicPressReleaseId: string) => {
129
136
  // Save record to Algolia
130
137
  const index = getIndex(indexKey);
131
138
  let record = null;
132
- const names: any = object?.name;
133
- if (names?.[defaultEnvironmentLocaleCode]) {
139
+ if (!isObjectToDelete(object, defaultEnvironmentLocaleCode)) {
134
140
  log(`Save object`);
135
141
  record = await index.saveObject(object);
136
142
  } else {
@@ -208,10 +214,10 @@ export const reindexPressReleases = async (
208
214
 
209
215
  const records = await getObjects(offset, limit, filterKey, filterValue);
210
216
  const objectsToSave = records.objects.filter(
211
- (object) => object?.name?.[defaultEnvironmentLocaleCode]
217
+ (object) => !isObjectToDelete(object, defaultEnvironmentLocaleCode)
212
218
  );
213
219
  const objectIdsToDelete = records.objects
214
- .filter((object) => !object?.name?.[defaultEnvironmentLocaleCode])
220
+ .filter((object) => isObjectToDelete(object, defaultEnvironmentLocaleCode))
215
221
  .map((object) => object.objectID);
216
222
 
217
223
  // Save records to Algolia
@@ -28,6 +28,13 @@ export type AlgoliaPressReviewRecord = {
28
28
  lastSyncDate?: string;
29
29
  };
30
30
 
31
+ const isObjectToDelete = (
32
+ object: any,
33
+ defaultEnvironmentLocaleCode: string
34
+ ) => {
35
+ return !object?.name?.[defaultEnvironmentLocaleCode];
36
+ };
37
+
31
38
  const getObject = async (
32
39
  topicPressReview: Entry
33
40
  ): Promise<AlgoliaPressReviewRecord> => {
@@ -122,8 +129,7 @@ export const reindexPressReview = async (topicPressReviewId: string) => {
122
129
  // Save record to Algolia
123
130
  const index = getIndex(indexKey);
124
131
  let record = null;
125
- const names: any = object?.name;
126
- if (names?.[defaultEnvironmentLocaleCode]) {
132
+ if (!isObjectToDelete(object, defaultEnvironmentLocaleCode)) {
127
133
  log(`Save object`);
128
134
  record = await index.saveObject(object);
129
135
  } else {
@@ -201,10 +207,10 @@ export const reindexPressReviews = async (
201
207
 
202
208
  const records = await getObjects(offset, limit, filterKey, filterValue);
203
209
  const objectsToSave = records.objects.filter(
204
- (object) => object?.name?.[defaultEnvironmentLocaleCode]
210
+ (object) => !isObjectToDelete(object, defaultEnvironmentLocaleCode)
205
211
  );
206
212
  const objectIdsToDelete = records.objects
207
- .filter((object) => !object?.name?.[defaultEnvironmentLocaleCode])
213
+ .filter((object) => isObjectToDelete(object, defaultEnvironmentLocaleCode))
208
214
  .map((object) => object.objectID);
209
215
 
210
216
  // Save records to Algolia
@@ -74,6 +74,13 @@ const pipedreamPDFGenerator = async (topicProductId: string) => {
74
74
  }
75
75
  };
76
76
 
77
+ const isObjectToDelete = (
78
+ object: any,
79
+ defaultEnvironmentLocaleCode: string
80
+ ) => {
81
+ return !object?.code || !object?.slugs?.[defaultEnvironmentLocaleCode];
82
+ };
83
+
77
84
  const getObject = async (
78
85
  topicProduct: Entry
79
86
  ): Promise<AlgoliaProductRecord> => {
@@ -341,6 +348,7 @@ export const reindexProduct = async (
341
348
 
342
349
  log(`reindexProduct - entryId: ${topicProductId} `);
343
350
 
351
+ const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
344
352
  const topicProduct = await getEntryByID(
345
353
  topicProductId,
346
354
  "topicProduct",
@@ -356,7 +364,7 @@ export const reindexProduct = async (
356
364
  // Save record to Algolia
357
365
  const index = getIndex(indexKey);
358
366
  let record = null;
359
- if (object?.code) {
367
+ if (!isObjectToDelete(object, defaultEnvironmentLocaleCode)) {
360
368
  log(`Save object`);
361
369
  record = await index.saveObject(object);
362
370
  if (generatePdf && record?.objectID) {
@@ -447,9 +455,12 @@ export const reindexProducts = async (
447
455
  limit,
448
456
  lastPimSyncDateGte
449
457
  );
450
- const objectsToSave = records.objects.filter((object) => object?.code);
458
+ const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
459
+ const objectsToSave = records.objects.filter(
460
+ (object) => !isObjectToDelete(object, defaultEnvironmentLocaleCode)
461
+ );
451
462
  const objectIdsToDelete = records.objects
452
- .filter((object) => !object?.code)
463
+ .filter((object) => isObjectToDelete(object, defaultEnvironmentLocaleCode))
453
464
  .map((object) => object.objectID);
454
465
 
455
466
  // Save records to Algolia
@@ -33,6 +33,13 @@ export type AlgoliaProjectRecord = {
33
33
  lastSyncDate?: string;
34
34
  };
35
35
 
36
+ const isObjectToDelete = (
37
+ object: any,
38
+ defaultEnvironmentLocaleCode: string
39
+ ) => {
40
+ return !object?.slugs?.[defaultEnvironmentLocaleCode];
41
+ };
42
+
36
43
  const getObject = async (
37
44
  topicProject: Entry
38
45
  ): Promise<AlgoliaProjectRecord> => {
@@ -166,8 +173,7 @@ export const reindexProject = async (topicProjectId: string) => {
166
173
  // Save record to Algolia
167
174
  const index = getIndex(indexKey);
168
175
  let record = null;
169
- const slugs: any = object?.slugs;
170
- if (slugs?.[defaultEnvironmentLocaleCode]) {
176
+ if (!isObjectToDelete(object, defaultEnvironmentLocaleCode)) {
171
177
  log(`Save object`);
172
178
  record = await index.saveObject(object);
173
179
  } else {
@@ -245,10 +251,10 @@ export const reindexProjects = async (
245
251
 
246
252
  const records = await getObjects(offset, limit, filterKey, filterValue);
247
253
  const objectsToSave = records.objects.filter(
248
- (object) => object?.slugs?.[defaultEnvironmentLocaleCode]
254
+ (object) => !isObjectToDelete(object, defaultEnvironmentLocaleCode)
249
255
  );
250
256
  const objectIdsToDelete = records.objects
251
- .filter((object) => !object?.slugs?.[defaultEnvironmentLocaleCode])
257
+ .filter((object) => isObjectToDelete(object, defaultEnvironmentLocaleCode))
252
258
  .map((object) => object.objectID);
253
259
 
254
260
  // Save records to Algolia
@@ -34,6 +34,13 @@ export type AlgoliaStoryRecord = {
34
34
  lastSyncDate?: string;
35
35
  };
36
36
 
37
+ const isObjectToDelete = (
38
+ object: any,
39
+ defaultEnvironmentLocaleCode: string
40
+ ) => {
41
+ return !object?.slugs?.[defaultEnvironmentLocaleCode];
42
+ };
43
+
37
44
  const getObject = async (topicStory: Entry): Promise<AlgoliaStoryRecord> => {
38
45
  const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
39
46
  log(`Sync the ${topicStory.sys.id} topicStory...`);
@@ -194,8 +201,7 @@ export const reindexStory = async (topicStoryId: string) => {
194
201
  // Save record to Algolia
195
202
  const index = getIndex(indexKey);
196
203
  let record = null;
197
- const slugs: any = object?.slugs;
198
- if (slugs?.[defaultEnvironmentLocaleCode]) {
204
+ if (isObjectToDelete(object, defaultEnvironmentLocaleCode)) {
199
205
  log(`Save object to ${index.indexName} index`);
200
206
  record = await index.saveObject(object);
201
207
  } else {
@@ -273,10 +279,10 @@ export const reindexStories = async (
273
279
 
274
280
  const records = await getObjects(offset, limit, filterKey, filterValue);
275
281
  const objectsToSave = records.objects.filter(
276
- (object) => object?.slugs?.[defaultEnvironmentLocaleCode]
282
+ (object) => !isObjectToDelete(object, defaultEnvironmentLocaleCode)
277
283
  );
278
284
  const objectIdsToDelete = records.objects
279
- .filter((object) => !object?.slugs?.[defaultEnvironmentLocaleCode])
285
+ .filter((object) => isObjectToDelete(object, defaultEnvironmentLocaleCode))
280
286
  .map((object) => object.objectID);
281
287
 
282
288
  // Save records to Algolia
@@ -231,6 +231,15 @@ const getProductFields = async (topicSubFamily: Entry): Promise<any> => {
231
231
  return productFields;
232
232
  };
233
233
 
234
+ const isObjectToDelete = (
235
+ object: any,
236
+ defaultEnvironmentLocaleCode: string
237
+ ) => {
238
+ return (
239
+ !object?.productFields || !object?.slugs?.[defaultEnvironmentLocaleCode]
240
+ );
241
+ };
242
+
234
243
  const getObject = async (
235
244
  topicSubFamily: Entry
236
245
  ): Promise<AlgoliaFamilyRecord> => {
@@ -375,12 +384,13 @@ export const reindexSubFamilies = async (
375
384
  `reindexSubFamilies - offset: ${offset} limit: ${limit} catalog: ${catalogCode}`
376
385
  );
377
386
 
387
+ const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
378
388
  const records = await getObjects(offset, limit, catalogCode);
379
389
  const objectsToSave = records.objects.filter(
380
- (object) => object.productFields
390
+ (object) => !isObjectToDelete(object, defaultEnvironmentLocaleCode)
381
391
  );
382
392
  const objectIdsToDelete = records.objects
383
- .filter((object) => !object?.productFields)
393
+ .filter((object) => isObjectToDelete(object, defaultEnvironmentLocaleCode))
384
394
  .map((object) => object.objectID);
385
395
 
386
396
  // Save records to Algolia
@@ -420,7 +430,8 @@ export const reindexSubFamily = async (topicSubFamilyEntryId: string) => {
420
430
  // Save record to Algolia
421
431
  const index = getIndex(indexKey);
422
432
  let record = null;
423
- if (object.productFields) {
433
+ const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
434
+ if (!isObjectToDelete(object, defaultEnvironmentLocaleCode)) {
424
435
  log(`Save object`);
425
436
  record = await index.saveObject(object);
426
437
  } else {
@@ -125,6 +125,10 @@ const getProductFields = async (
125
125
  return productFields;
126
126
  };
127
127
 
128
+ const isObjectToDelete = (object: any) => {
129
+ return Object.entries(object).length === 1;
130
+ };
131
+
128
132
  const getObject = async (
129
133
  topicSubModel: string | Entry
130
134
  ): Promise<AlgoliaSubModelRecord> => {
@@ -238,10 +242,6 @@ const getObject = async (
238
242
  return record;
239
243
  };
240
244
 
241
- const isObjectToDelete = (object: any) => {
242
- return Object.entries(object).length === 1;
243
- };
244
-
245
245
  export const reindexSubModel = async (topicSubModelId: string) => {
246
246
  const timeStart = new Date();
247
247
 
package/src/index.ts CHANGED
@@ -40,6 +40,7 @@ export {
40
40
  getProductAutodescription,
41
41
  setProductAutodescriptionByTopicId,
42
42
  removeProductFromColorVariantsByProductLine,
43
+ removeAllProductModelProductRelations,
43
44
  } from "./pim/methods/products";
44
45
  // export {
45
46
  // createOrUpdateCatalogPages,
@@ -106,6 +107,7 @@ export {
106
107
  reindexPressReleases,
107
108
  removePressReleaseObject,
108
109
  } from "./algolia/pressRelease";
110
+ export { reindexPost, reindexPosts, removePostObject } from "./algolia/news";
109
111
  export { importDownloads } from "./downloads/import";
110
112
  export { getLocalISOTime } from "./utils";
111
113
  export { getStaticDailyProducts } from "./pim/endpoints";
@@ -2178,3 +2178,59 @@ export const removeProductFromColorVariantsByProductLine = async (
2178
2178
  }
2179
2179
  }
2180
2180
  };
2181
+
2182
+ /**
2183
+ * Remove a specific model from all product model relations
2184
+ * NOTE: require the reindex of all product updated
2185
+ *
2186
+ * @param modelCode
2187
+ */
2188
+ export const removeAllProductModelProductRelations = async (
2189
+ modelCode: string
2190
+ ) => {
2191
+ log(`removeAllProductModelProductRelations - modelCode: ${modelCode}`);
2192
+ const env = await getEnvironment();
2193
+ const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
2194
+ const { items } = await env.getEntries({
2195
+ content_type: "topicProduct",
2196
+ locale: defEnvLocaleCode,
2197
+ include: 2,
2198
+ links_to_entry: modelCode,
2199
+ limit: 1000,
2200
+ });
2201
+
2202
+ log(`Founded ${items.length} products`);
2203
+
2204
+ const allProductModelFields = [
2205
+ "modelsArchitectural",
2206
+ "modelsOutdoor",
2207
+ "modelsDecorative",
2208
+ ];
2209
+ for (let item of items) {
2210
+ for (const modelFieldKey of allProductModelFields) {
2211
+ if (
2212
+ item.fields?.[modelFieldKey]?.[defEnvLocaleCode].find(
2213
+ (model: CfSys) => model.sys.id === modelCode
2214
+ )
2215
+ ) {
2216
+ item.fields[modelFieldKey][defEnvLocaleCode] = item.fields[
2217
+ modelFieldKey
2218
+ ][defEnvLocaleCode].filter(
2219
+ (model: CfSys) => model.sys.id !== modelCode
2220
+ );
2221
+ }
2222
+ }
2223
+
2224
+ const productCode = item.fields.code[defEnvLocaleCode];
2225
+ if (item.isArchived()) {
2226
+ log(`Product with code ${productCode} is archived`, "WARN");
2227
+ } else {
2228
+ item = await item.update();
2229
+ log(`Updated product ${productCode}`);
2230
+ // log(`"${productCode}",`);
2231
+ }
2232
+ if (item.isPublished()) {
2233
+ item = await item.publish();
2234
+ }
2235
+ }
2236
+ };