pim-import 2.59.0 → 2.61.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 +36 -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 +141 -0
  10. package/dist/algolia/news.js.map +1 -0
  11. package/dist/algolia/pipedreamReindex.js +0 -1
  12. package/dist/algolia/pipedreamReindex.js.map +1 -1
  13. package/dist/algolia/pressRelease.js +140 -0
  14. package/dist/algolia/pressRelease.js.map +1 -0
  15. package/dist/algolia/pressReview.js +6 -4
  16. package/dist/algolia/pressReview.js.map +1 -1
  17. package/dist/algolia/products.js +8 -3
  18. package/dist/algolia/products.js.map +1 -1
  19. package/dist/algolia/projects.js +6 -4
  20. package/dist/algolia/projects.js.map +1 -1
  21. package/dist/algolia/stories.js +6 -4
  22. package/dist/algolia/stories.js.map +1 -1
  23. package/dist/algolia/subFamilies.js +8 -4
  24. package/dist/algolia/subFamilies.js.map +1 -1
  25. package/dist/algolia/subModels.js +3 -3
  26. package/dist/algolia/subModels.js.map +1 -1
  27. package/dist/index.js +9 -1
  28. package/dist/index.js.map +1 -1
  29. package/package.json +1 -1
  30. package/src/algolia/config.ts +39 -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 +228 -0
  35. package/src/algolia/pipedreamReindex.ts +0 -1
  36. package/src/algolia/pressRelease.ts +241 -0
  37. package/src/algolia/pressReview.ts +10 -4
  38. package/src/algolia/products.ts +14 -3
  39. package/src/algolia/projects.ts +10 -4
  40. package/src/algolia/stories.ts +10 -4
  41. package/src/algolia/subFamilies.ts +14 -4
  42. package/src/algolia/subModels.ts +4 -4
  43. package/src/index.ts +6 -0
@@ -123,6 +123,13 @@ const getModelAutodescription = async (productLineCode: string) => {
123
123
  );
124
124
  };
125
125
 
126
+ const isObjectToDelete = (
127
+ object: any,
128
+ defaultEnvironmentLocaleCode: string
129
+ ) => {
130
+ return !object?.slugs?.[defaultEnvironmentLocaleCode];
131
+ };
132
+
126
133
  const getObject = async (
127
134
  topicModel: string | Entry
128
135
  ): Promise<AlgoliaModelRecord> => {
@@ -265,21 +272,18 @@ const getObject = async (
265
272
  return record;
266
273
  };
267
274
 
268
- const isObjectToDelete = (object: any) => {
269
- return Object.entries(object).length === 1;
270
- };
271
-
272
275
  export const reindexModel = async (topicModelId: string) => {
273
276
  const timeStart = new Date();
274
277
 
275
278
  log(`reindexModel - entryId: ${topicModelId} `);
276
279
 
280
+ const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
277
281
  const object = await getObject(topicModelId);
278
282
 
279
283
  // Save record to Algolia
280
284
  const index = getIndex(indexKey);
281
285
  let record = null;
282
- if (!isObjectToDelete(object)) {
286
+ if (!isObjectToDelete(object, defaultEnvironmentLocaleCode)) {
283
287
  log(`Save object`);
284
288
  record = await index.saveObject(object);
285
289
  } else {
@@ -342,13 +346,14 @@ export const reindexModels = async (
342
346
  log(
343
347
  `reindexModels - offset: ${offset} limit: ${limit} catalogCode: ${catalogCode}`
344
348
  );
349
+ const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
345
350
 
346
351
  const records = await getObjects(offset, limit, catalogCode);
347
352
  const objectsToSave = records.objects.filter(
348
- (object) => !isObjectToDelete(object)
353
+ (object) => !isObjectToDelete(object, defaultEnvironmentLocaleCode)
349
354
  );
350
355
  const objectIdsToDelete = records.objects
351
- .filter((object) => isObjectToDelete(object))
356
+ .filter((object) => isObjectToDelete(object, defaultEnvironmentLocaleCode))
352
357
  .map((object) => object.objectID);
353
358
 
354
359
  // Save records to Algolia
@@ -0,0 +1,228 @@
1
+ import { log } from "../libs/logs";
2
+ import {
3
+ getClient,
4
+ getEnvironmentDefaultLocaleCode,
5
+ getEntryByID,
6
+ getTopicPage,
7
+ } from "../libs/contentful-cda";
8
+ import { getIndex, AvailableIndicesKey, removeIndexObject } from "./config";
9
+ import { getLocalISOTime, secondBetweenTwoDate } from "../utils";
10
+ import type { Entry } from "contentful-management/dist/typings/entities/entry";
11
+ import {
12
+ CfLocalizedEntryField,
13
+ AlgoliaPaginateRecords,
14
+ WrapperImageFields,
15
+ } from "../types";
16
+ import { getWrapperImgixFields } from "../libs/imgix";
17
+
18
+ const indexKey: AvailableIndicesKey = "news";
19
+
20
+ export type AlgoliaPostRecord = {
21
+ objectID: string;
22
+ name?: CfLocalizedEntryField;
23
+ slugs?: {};
24
+ previewExcerpt?: string;
25
+ thumbnailImageImgix?: WrapperImageFields | {};
26
+ fullScreenImageImgix?: WrapperImageFields | {};
27
+ visualizationDate?: string;
28
+ lastSyncDate?: string;
29
+ };
30
+
31
+ const isObjectToDelete = (
32
+ object: any,
33
+ defaultEnvironmentLocaleCode: string
34
+ ) => {
35
+ return !object?.slugs?.[defaultEnvironmentLocaleCode];
36
+ };
37
+
38
+ const getObject = async (topicNews: Entry): Promise<AlgoliaPostRecord> => {
39
+ const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
40
+ log(`Sync the ${topicNews.sys.id} topicNews...`);
41
+ let topicNewsWithFields: Entry = topicNews;
42
+
43
+ if (!topicNewsWithFields?.fields) {
44
+ log(`Get the ${topicNews.sys.id} topicNews details...`);
45
+ topicNewsWithFields = await getEntryByID(topicNews.sys.id, "topicNews");
46
+ }
47
+
48
+ if (!topicNewsWithFields) {
49
+ log(`The topicNews ${topicNews.sys.id} not found`, "WARN");
50
+
51
+ const recordFail: AlgoliaPostRecord = {
52
+ objectID: topicNews?.sys?.id,
53
+ };
54
+
55
+ return recordFail; // return objectID to delete the record if it exists
56
+ }
57
+
58
+ log(`Get page details...`);
59
+ const page = await getTopicPage(topicNews.sys.id, "fields.slug");
60
+ const slugs = page?.fields.slug || {};
61
+
62
+ log(`Get thumbnail imgix details...`);
63
+ let thumbnailImageImgix = {};
64
+ const thumbnailImgixWrapperImgixID =
65
+ topicNewsWithFields?.fields?.thumbnailImageImgix?.[
66
+ defaultEnvironmentLocaleCode
67
+ ]?.sys.id;
68
+ if (thumbnailImgixWrapperImgixID) {
69
+ thumbnailImageImgix = await getWrapperImgixFields(
70
+ thumbnailImgixWrapperImgixID
71
+ );
72
+ } else {
73
+ log(`No thumbnail imgix found`, "WARN");
74
+ }
75
+
76
+ log(`Get fullScreenImageImgix imgix details...`);
77
+ let fullScreenImageImgix = {};
78
+ const fullScreenImageImgixWrapperImgixID =
79
+ topicNewsWithFields?.fields?.fullScreenImageImgix?.[
80
+ defaultEnvironmentLocaleCode
81
+ ]?.sys.id;
82
+ if (fullScreenImageImgixWrapperImgixID) {
83
+ fullScreenImageImgix = await getWrapperImgixFields(
84
+ fullScreenImageImgixWrapperImgixID
85
+ );
86
+ } else {
87
+ log(`No fullScreenImageImgix found`, "WARN");
88
+ }
89
+
90
+ // Single record
91
+ const record: AlgoliaPostRecord = {
92
+ objectID: topicNewsWithFields.sys.id,
93
+ name:
94
+ topicNewsWithFields?.fields?.title?.[defaultEnvironmentLocaleCode] || "",
95
+ slugs,
96
+ thumbnailImageImgix,
97
+ fullScreenImageImgix,
98
+ visualizationDate:
99
+ topicNewsWithFields?.fields?.visualizationDate?.[
100
+ defaultEnvironmentLocaleCode
101
+ ] || "",
102
+ lastSyncDate: getLocalISOTime(),
103
+ };
104
+
105
+ return record;
106
+ };
107
+
108
+ export const reindexPost = async (topicNewsId: string) => {
109
+ const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
110
+ const timeStart = new Date();
111
+
112
+ log(`reindexPost - entryId: ${topicNewsId} `);
113
+
114
+ const topicNews = await getEntryByID(topicNewsId, "topicNews");
115
+
116
+ if (!topicNews) {
117
+ log(`No topicNews found with id ${topicNewsId}`, "WARN");
118
+ return false;
119
+ }
120
+
121
+ const object = await getObject(topicNews);
122
+
123
+ // Save record to Algolia
124
+ const index = getIndex(indexKey);
125
+ let record = null;
126
+ if (!isObjectToDelete(object, defaultEnvironmentLocaleCode)) {
127
+ log(`Save object`);
128
+ record = await index.saveObject(object);
129
+ } else {
130
+ log(`Delete object`);
131
+ record = await index.deleteObject(object.objectID);
132
+ }
133
+ const timeEnd = new Date();
134
+ const seconds = secondBetweenTwoDate(timeStart, timeEnd);
135
+ log(`Execution time: ${seconds} seconds`);
136
+
137
+ return { ...record, ...object };
138
+ };
139
+
140
+ /**
141
+ * Get Objects
142
+ *
143
+ * @param offset
144
+ * @param limit
145
+ * @param filterKey
146
+ * @param filterValue
147
+ * @returns
148
+ */
149
+ const getObjects = async (
150
+ offset: number,
151
+ limit: number,
152
+ filterKey?: string,
153
+ filterValue?: string
154
+ ): Promise<AlgoliaPaginateRecords> => {
155
+ const client = await getClient();
156
+
157
+ const opts: any = {
158
+ content_type: "topicNews",
159
+ limit,
160
+ skip: offset,
161
+ locale: "*",
162
+ // select: "",
163
+ };
164
+ if (filterKey && filterValue) {
165
+ opts[filterKey] = filterValue;
166
+ }
167
+ const { items, total } = await client.getEntries(opts);
168
+
169
+ const objects: AlgoliaPostRecord[] = [];
170
+ let count: number = Number(offset);
171
+ for (const topicNews of items) {
172
+ log(`${++count} of ${total}`, "INFO");
173
+ const timeStart = new Date();
174
+ const record = await getObject(topicNews);
175
+ const timeEnd = new Date();
176
+ const seconds = secondBetweenTwoDate(timeStart, timeEnd);
177
+ log(`Execution time: ${seconds} seconds`);
178
+ objects.push(record);
179
+ }
180
+
181
+ return {
182
+ objects,
183
+ offset: Number(offset) + Number(limit),
184
+ limit: Number(limit),
185
+ completed: count >= total, // if is true the import is completed
186
+ total,
187
+ };
188
+ };
189
+
190
+ export const reindexPosts = async (
191
+ offset: number = 0,
192
+ limit: number = 50,
193
+ filterKey: string = "",
194
+ filterValue: string = ""
195
+ ) => {
196
+ const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
197
+ const timeStart = new Date();
198
+ log(
199
+ `reindexPosts - filterKey: ${filterKey} filterValue: ${filterValue} offset: ${offset} limit: ${limit} `
200
+ );
201
+
202
+ const records = await getObjects(offset, limit, filterKey, filterValue);
203
+ const objectsToSave = records.objects.filter(
204
+ (object) => !isObjectToDelete(object, defaultEnvironmentLocaleCode)
205
+ );
206
+ const objectIdsToDelete = records.objects
207
+ .filter((object) => isObjectToDelete(object, defaultEnvironmentLocaleCode))
208
+ .map((object) => object.objectID);
209
+
210
+ // Save records to Algolia
211
+ const index = getIndex(indexKey);
212
+ log(`Save ${objectsToSave.length} objects to ${index.indexName} index`);
213
+ const savedObjectIDs = await index.saveObjects(objectsToSave);
214
+ log(
215
+ `Delete ${objectIdsToDelete.length} objects from ${index.indexName} index`
216
+ );
217
+ const deletedObjectIDs = await index.deleteObjects(objectIdsToDelete);
218
+
219
+ const timeEnd = new Date();
220
+ const seconds = secondBetweenTwoDate(timeStart, timeEnd);
221
+ log(`Execution time: ${seconds} seconds`);
222
+
223
+ return { ...records, ...savedObjectIDs, ...deletedObjectIDs };
224
+ };
225
+
226
+ export const removePostObject = async (objectId: string) => {
227
+ return removeIndexObject(objectId, indexKey);
228
+ };
@@ -19,7 +19,6 @@ export const pipedreamReindex = async (
19
19
  );
20
20
  return;
21
21
  }
22
- console.log(`reindexType: ${reindexType} catalogCode: ${catalogCode}`);
23
22
 
24
23
  axios.post(process.env.FPI_PIPEDREAM_ALGOLIA, {
25
24
  isReindexByImport: true,
@@ -0,0 +1,241 @@
1
+ import { log } from "../libs/logs";
2
+ import {
3
+ getClient,
4
+ getEnvironmentDefaultLocaleCode,
5
+ getEntryByID,
6
+ getTopicDetails,
7
+ } from "../libs/contentful-cda";
8
+ import { getIndex, AvailableIndicesKey, removeIndexObject } from "./config";
9
+ import { getLocalISOTime, secondBetweenTwoDate } from "../utils";
10
+ import type { Entry } from "contentful-management/dist/typings/entities/entry";
11
+ import {
12
+ CfLocalizedEntryField,
13
+ AlgoliaPaginateRecords,
14
+ WrapperImageFields,
15
+ TopicDetailsResponse,
16
+ CfSys,
17
+ } from "../types";
18
+ import { getWrapperImgixFields } from "../libs/imgix";
19
+ import { getAssetsByComponentAssetIds } from "./downloads";
20
+
21
+ const indexKey: AvailableIndicesKey = "pressRelease";
22
+
23
+ export type AlgoliaPressReleaseRecord = {
24
+ objectID: string;
25
+ name?: CfLocalizedEntryField;
26
+ description?: string;
27
+ thumbnailImgix?: WrapperImageFields | {};
28
+ lastSyncDate?: string;
29
+ category?: TopicDetailsResponse;
30
+ assets?: {};
31
+ visualizationDate?: string;
32
+ };
33
+
34
+ const isObjectToDelete = (
35
+ object: any,
36
+ defaultEnvironmentLocaleCode: string
37
+ ) => {
38
+ return !object?.name?.[defaultEnvironmentLocaleCode];
39
+ };
40
+
41
+ const getObject = async (
42
+ topicPressRelease: Entry
43
+ ): Promise<AlgoliaPressReleaseRecord> => {
44
+ const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
45
+ log(`Sync the ${topicPressRelease.sys.id} topicPressRelease...`);
46
+ let topicPressReleaseWithFields: Entry = topicPressRelease;
47
+
48
+ if (!topicPressReleaseWithFields?.fields) {
49
+ log(`Get the ${topicPressRelease.sys.id} topicPressRelease details...`);
50
+ topicPressReleaseWithFields = await getEntryByID(
51
+ topicPressRelease.sys.id,
52
+ "topicPressRelease"
53
+ );
54
+ }
55
+
56
+ if (!topicPressReleaseWithFields) {
57
+ log(`The topicPressRelease ${topicPressRelease.sys.id} not found`, "WARN");
58
+
59
+ const recordFail: AlgoliaPressReleaseRecord = {
60
+ objectID: topicPressRelease?.sys?.id,
61
+ };
62
+
63
+ return recordFail; // return objectID to delete the record if it exists
64
+ }
65
+
66
+ log(`Get thumbnail imgix details...`);
67
+ let thumbnailImgix = {};
68
+ const thumbnailImgixWrapperImgixID =
69
+ topicPressReleaseWithFields?.fields?.thumbnailImgix?.[
70
+ defaultEnvironmentLocaleCode
71
+ ]?.sys.id;
72
+ if (thumbnailImgixWrapperImgixID) {
73
+ thumbnailImgix = await getWrapperImgixFields(thumbnailImgixWrapperImgixID);
74
+ } else {
75
+ log(`No thumbnail imgix found`, "WARN");
76
+ }
77
+
78
+ log(`Get category details...`);
79
+ const category = await getTopicDetails(
80
+ topicPressReleaseWithFields,
81
+ "category",
82
+ "topicPressReleaseCategory",
83
+ true,
84
+ false,
85
+ false,
86
+ true
87
+ );
88
+
89
+ log(`Get assets details...`);
90
+ let assets: any = [];
91
+ const componentAssets =
92
+ topicPressReleaseWithFields?.fields?.assets?.[defaultEnvironmentLocaleCode];
93
+ if (componentAssets) {
94
+ const componentAssetIds = componentAssets.map(
95
+ (item: CfSys) => item?.sys?.id
96
+ );
97
+ assets = await getAssetsByComponentAssetIds(componentAssetIds);
98
+ }
99
+
100
+ // Single record
101
+ const record: AlgoliaPressReleaseRecord = {
102
+ objectID: topicPressReleaseWithFields.sys.id,
103
+ name: topicPressReleaseWithFields?.fields?.name,
104
+ description: topicPressReleaseWithFields?.fields?.description,
105
+ thumbnailImgix,
106
+ category: category?.[0],
107
+ assets,
108
+ visualizationDate:
109
+ topicPressReleaseWithFields?.fields?.visualizationDate?.[
110
+ defaultEnvironmentLocaleCode
111
+ ] || "",
112
+ lastSyncDate: getLocalISOTime(),
113
+ };
114
+
115
+ return record;
116
+ };
117
+
118
+ export const reindexPressRelease = async (topicPressReleaseId: string) => {
119
+ const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
120
+ const timeStart = new Date();
121
+
122
+ log(`reindexPressRelease - entryId: ${topicPressReleaseId} `);
123
+
124
+ const topicPressRelease = await getEntryByID(
125
+ topicPressReleaseId,
126
+ "topicPressRelease"
127
+ );
128
+
129
+ if (!topicPressRelease) {
130
+ log(`No topicPressReleaseId found with id ${topicPressReleaseId}`, "WARN");
131
+ return false;
132
+ }
133
+
134
+ const object = await getObject(topicPressRelease);
135
+
136
+ // Save record to Algolia
137
+ const index = getIndex(indexKey);
138
+ let record = null;
139
+ if (!isObjectToDelete(object, defaultEnvironmentLocaleCode)) {
140
+ log(`Save object`);
141
+ record = await index.saveObject(object);
142
+ } else {
143
+ log(`Delete object`);
144
+ record = await index.deleteObject(object.objectID);
145
+ }
146
+ const timeEnd = new Date();
147
+ const seconds = secondBetweenTwoDate(timeStart, timeEnd);
148
+ log(`Execution time: ${seconds} seconds`);
149
+
150
+ return { ...record, ...object };
151
+ };
152
+
153
+ /**
154
+ * Get Objects
155
+ *
156
+ * @param offset
157
+ * @param limit
158
+ * @param filterKey
159
+ * @param filterValue
160
+ * @returns
161
+ */
162
+ const getObjects = async (
163
+ offset: number,
164
+ limit: number,
165
+ filterKey?: string,
166
+ filterValue?: string
167
+ ): Promise<AlgoliaPaginateRecords> => {
168
+ const client = await getClient();
169
+
170
+ const opts: any = {
171
+ content_type: "topicPressRelease",
172
+ limit,
173
+ skip: offset,
174
+ locale: "*",
175
+ // select: "",
176
+ };
177
+ if (filterKey && filterValue) {
178
+ opts[filterKey] = filterValue;
179
+ }
180
+ const { items, total } = await client.getEntries(opts);
181
+
182
+ const objects: AlgoliaPressReleaseRecord[] = [];
183
+ let count: number = Number(offset);
184
+ for (const topicPressRelease of items) {
185
+ log(`${++count} of ${total}`, "INFO");
186
+ const timeStart = new Date();
187
+ const record = await getObject(topicPressRelease);
188
+ const timeEnd = new Date();
189
+ const seconds = secondBetweenTwoDate(timeStart, timeEnd);
190
+ log(`Execution time: ${seconds} seconds`);
191
+ objects.push(record);
192
+ }
193
+
194
+ return {
195
+ objects,
196
+ offset: Number(offset) + Number(limit),
197
+ limit: Number(limit),
198
+ completed: count >= total, // if is true the import is completed
199
+ total,
200
+ };
201
+ };
202
+
203
+ export const reindexPressReleases = async (
204
+ offset: number = 0,
205
+ limit: number = 50,
206
+ filterKey: string = "",
207
+ filterValue: string = ""
208
+ ) => {
209
+ const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
210
+ const timeStart = new Date();
211
+ log(
212
+ `reindexPressReleases - filterKey: ${filterKey} filterValue: ${filterValue} offset: ${offset} limit: ${limit} `
213
+ );
214
+
215
+ const records = await getObjects(offset, limit, filterKey, filterValue);
216
+ const objectsToSave = records.objects.filter(
217
+ (object) => !isObjectToDelete(object, defaultEnvironmentLocaleCode)
218
+ );
219
+ const objectIdsToDelete = records.objects
220
+ .filter((object) => isObjectToDelete(object, defaultEnvironmentLocaleCode))
221
+ .map((object) => object.objectID);
222
+
223
+ // Save records to Algolia
224
+ const index = getIndex(indexKey);
225
+ log(`Save ${objectsToSave.length} objects to ${index.indexName} index`);
226
+ const savedObjectIDs = await index.saveObjects(objectsToSave);
227
+ log(
228
+ `Delete ${objectIdsToDelete.length} objects from ${index.indexName} index`
229
+ );
230
+ const deletedObjectIDs = await index.deleteObjects(objectIdsToDelete);
231
+
232
+ const timeEnd = new Date();
233
+ const seconds = secondBetweenTwoDate(timeStart, timeEnd);
234
+ log(`Execution time: ${seconds} seconds`);
235
+
236
+ return { ...records, ...savedObjectIDs, ...deletedObjectIDs };
237
+ };
238
+
239
+ export const removePressReleaseObject = async (objectId: string) => {
240
+ return removeIndexObject(objectId, indexKey);
241
+ };
@@ -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?.slugs?.[defaultEnvironmentLocaleCode]
210
+ (object) => !isObjectToDelete(object, defaultEnvironmentLocaleCode)
205
211
  );
206
212
  const objectIdsToDelete = records.objects
207
- .filter((object) => !object?.slugs?.[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