pim-import 2.58.2 → 2.60.2

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 +9 -5
  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/pipedreamReindex.js +0 -1
  10. package/dist/algolia/pipedreamReindex.js.map +1 -1
  11. package/dist/algolia/pressRelease.js +140 -0
  12. package/dist/algolia/pressRelease.js.map +1 -0
  13. package/dist/algolia/pressReview.js +142 -0
  14. package/dist/algolia/pressReview.js.map +1 -0
  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 -4
  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 +9 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/pim/methods/products.js +10 -8
  28. package/dist/pim/methods/products.js.map +1 -1
  29. package/package.json +1 -1
  30. package/src/algolia/config.ts +39 -1
  31. package/src/algolia/downloads.ts +12 -4
  32. package/src/algolia/families.ts +14 -3
  33. package/src/algolia/models.ts +12 -7
  34. package/src/algolia/pipedreamReindex.ts +0 -1
  35. package/src/algolia/pressRelease.ts +241 -0
  36. package/src/algolia/pressReview.ts +234 -0
  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 -4
  41. package/src/algolia/subModels.ts +4 -4
  42. package/src/index.ts +10 -0
  43. package/src/pim/methods/products.ts +10 -8
@@ -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
+ };
@@ -0,0 +1,234 @@
1
+ import { log } from "../libs/logs";
2
+ import {
3
+ getClient,
4
+ getEnvironmentDefaultLocaleCode,
5
+ getEntryByID,
6
+ } from "../libs/contentful-cda";
7
+ import { getIndex, AvailableIndicesKey, removeIndexObject } from "./config";
8
+ import { getLocalISOTime, secondBetweenTwoDate } from "../utils";
9
+ import type { Entry } from "contentful-management/dist/typings/entities/entry";
10
+ import {
11
+ CfLocalizedEntryField,
12
+ AlgoliaPaginateRecords,
13
+ WrapperImageFields,
14
+ } from "../types";
15
+ import { getWrapperImgixFields } from "../libs/imgix";
16
+ import { getAssetsByComponentAssetIds } from "./downloads";
17
+
18
+ const indexKey: AvailableIndicesKey = "pressReviews";
19
+
20
+ export type AlgoliaPressReviewRecord = {
21
+ objectID: string;
22
+ name?: CfLocalizedEntryField;
23
+ yearOfRelease?: string;
24
+ monthOfRelease?: string;
25
+ country?: string;
26
+ thumbnailImgix?: WrapperImageFields | {};
27
+ asset?: {};
28
+ lastSyncDate?: string;
29
+ };
30
+
31
+ const isObjectToDelete = (
32
+ object: any,
33
+ defaultEnvironmentLocaleCode: string
34
+ ) => {
35
+ return !object?.name?.[defaultEnvironmentLocaleCode];
36
+ };
37
+
38
+ const getObject = async (
39
+ topicPressReview: Entry
40
+ ): Promise<AlgoliaPressReviewRecord> => {
41
+ const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
42
+ log(`Sync the ${topicPressReview.sys.id} topicPressReview...`);
43
+ let topicPressReviewWithFields: Entry = topicPressReview;
44
+
45
+ if (!topicPressReviewWithFields?.fields) {
46
+ log(`Get the ${topicPressReview.sys.id} topicPressReview details...`);
47
+ topicPressReviewWithFields = await getEntryByID(
48
+ topicPressReview.sys.id,
49
+ "topicPressReview"
50
+ );
51
+ }
52
+
53
+ if (!topicPressReviewWithFields) {
54
+ log(`The topicPressReview ${topicPressReview.sys.id} not found`, "WARN");
55
+
56
+ const recordFail: AlgoliaPressReviewRecord = {
57
+ objectID: topicPressReview?.sys?.id,
58
+ };
59
+
60
+ return recordFail; // return objectID to delete the record if it exists
61
+ }
62
+
63
+ log(`Get thumbnail imgix details...`);
64
+ let thumbnailImgix = {};
65
+ const thumbnailImgixWrapperImgixID =
66
+ topicPressReviewWithFields?.fields?.thumbnailImageImgix?.[
67
+ defaultEnvironmentLocaleCode
68
+ ]?.sys.id;
69
+ if (thumbnailImgixWrapperImgixID) {
70
+ thumbnailImgix = await getWrapperImgixFields(thumbnailImgixWrapperImgixID);
71
+ } else {
72
+ log(`No thumbnail imgix found`, "WARN");
73
+ }
74
+
75
+ log(`Get asset details...`);
76
+ const fileId =
77
+ topicPressReviewWithFields?.fields?.asset?.[defaultEnvironmentLocaleCode]
78
+ ?.sys?.id;
79
+ let asset = {};
80
+ if (fileId) {
81
+ const componentAssetIds = await getAssetsByComponentAssetIds([fileId]);
82
+ asset = componentAssetIds ? componentAssetIds[0] : {};
83
+ } else {
84
+ log(`No asset found`, "WARN");
85
+ }
86
+
87
+ // Single record
88
+ const record: AlgoliaPressReviewRecord = {
89
+ objectID: topicPressReviewWithFields.sys.id,
90
+ name: topicPressReviewWithFields?.fields?.name,
91
+ yearOfRelease:
92
+ topicPressReviewWithFields?.fields?.yearOfRelease?.[
93
+ defaultEnvironmentLocaleCode
94
+ ] || "",
95
+ monthOfRelease:
96
+ topicPressReviewWithFields?.fields?.monthOfRelease?.[
97
+ defaultEnvironmentLocaleCode
98
+ ] || "",
99
+ country:
100
+ topicPressReviewWithFields?.fields?.country?.[
101
+ defaultEnvironmentLocaleCode
102
+ ] || "",
103
+ thumbnailImgix,
104
+ asset,
105
+ lastSyncDate: getLocalISOTime(),
106
+ };
107
+
108
+ return record;
109
+ };
110
+
111
+ export const reindexPressReview = async (topicPressReviewId: string) => {
112
+ const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
113
+ const timeStart = new Date();
114
+
115
+ log(`reindexPressReview - entryId: ${topicPressReviewId} `);
116
+
117
+ const topicPressReview = await getEntryByID(
118
+ topicPressReviewId,
119
+ "topicPressReview"
120
+ );
121
+
122
+ if (!topicPressReview) {
123
+ log(`No topicPressReviewId found with id ${topicPressReviewId}`, "WARN");
124
+ return false;
125
+ }
126
+
127
+ const object = await getObject(topicPressReview);
128
+
129
+ // Save record to Algolia
130
+ const index = getIndex(indexKey);
131
+ let record = null;
132
+ if (!isObjectToDelete(object, defaultEnvironmentLocaleCode)) {
133
+ log(`Save object`);
134
+ record = await index.saveObject(object);
135
+ } else {
136
+ log(`Delete object`);
137
+ record = await index.deleteObject(object.objectID);
138
+ }
139
+ const timeEnd = new Date();
140
+ const seconds = secondBetweenTwoDate(timeStart, timeEnd);
141
+ log(`Execution time: ${seconds} seconds`);
142
+
143
+ return { ...record, ...object };
144
+ };
145
+
146
+ /**
147
+ * Get Objects
148
+ *
149
+ * @param offset
150
+ * @param limit
151
+ * @param filterKey
152
+ * @param filterValue
153
+ * @returns
154
+ */
155
+ const getObjects = async (
156
+ offset: number,
157
+ limit: number,
158
+ filterKey?: string,
159
+ filterValue?: string
160
+ ): Promise<AlgoliaPaginateRecords> => {
161
+ const client = await getClient();
162
+
163
+ const opts: any = {
164
+ content_type: "topicPressReview",
165
+ limit,
166
+ skip: offset,
167
+ locale: "*",
168
+ // select: "",
169
+ };
170
+ if (filterKey && filterValue) {
171
+ opts[filterKey] = filterValue;
172
+ }
173
+ const { items, total } = await client.getEntries(opts);
174
+
175
+ const objects: AlgoliaPressReviewRecord[] = [];
176
+ let count: number = Number(offset);
177
+ for (const topicPressReview of items) {
178
+ log(`${++count} of ${total}`, "INFO");
179
+ const timeStart = new Date();
180
+ const record = await getObject(topicPressReview);
181
+ const timeEnd = new Date();
182
+ const seconds = secondBetweenTwoDate(timeStart, timeEnd);
183
+ log(`Execution time: ${seconds} seconds`);
184
+ objects.push(record);
185
+ }
186
+
187
+ return {
188
+ objects,
189
+ offset: Number(offset) + Number(limit),
190
+ limit: Number(limit),
191
+ completed: count >= total, // if is true the import is completed
192
+ total,
193
+ };
194
+ };
195
+
196
+ export const reindexPressReviews = async (
197
+ offset: number = 0,
198
+ limit: number = 50,
199
+ filterKey: string = "",
200
+ filterValue: string = ""
201
+ ) => {
202
+ const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
203
+ const timeStart = new Date();
204
+ log(
205
+ `reindexPressReviews - filterKey: ${filterKey} filterValue: ${filterValue} offset: ${offset} limit: ${limit} `
206
+ );
207
+
208
+ const records = await getObjects(offset, limit, filterKey, filterValue);
209
+ const objectsToSave = records.objects.filter(
210
+ (object) => !isObjectToDelete(object, defaultEnvironmentLocaleCode)
211
+ );
212
+ const objectIdsToDelete = records.objects
213
+ .filter((object) => isObjectToDelete(object, defaultEnvironmentLocaleCode))
214
+ .map((object) => object.objectID);
215
+
216
+ // Save records to Algolia
217
+ const index = getIndex(indexKey);
218
+ log(`Save ${objectsToSave.length} objects to ${index.indexName} index`);
219
+ const savedObjectIDs = await index.saveObjects(objectsToSave);
220
+ log(
221
+ `Delete ${objectIdsToDelete.length} objects from ${index.indexName} index`
222
+ );
223
+ const deletedObjectIDs = await index.deleteObjects(objectIdsToDelete);
224
+
225
+ const timeEnd = new Date();
226
+ const seconds = secondBetweenTwoDate(timeStart, timeEnd);
227
+ log(`Execution time: ${seconds} seconds`);
228
+
229
+ return { ...records, ...savedObjectIDs, ...deletedObjectIDs };
230
+ };
231
+
232
+ export const removePressReviewObject = async (objectId: string) => {
233
+ return removeIndexObject(objectId, indexKey);
234
+ };
@@ -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
@@ -118,7 +118,6 @@ const getProductFields = async (topicSubFamily: Entry): Promise<any> => {
118
118
  ).toLowerCase()
119
119
  );
120
120
  if (!catalogName) {
121
- console.log(topicSubFamily.fields.catalog);
122
121
  log(`Cannot find catalog name`, "WARN");
123
122
  return {};
124
123
  }
@@ -232,6 +231,15 @@ const getProductFields = async (topicSubFamily: Entry): Promise<any> => {
232
231
  return productFields;
233
232
  };
234
233
 
234
+ const isObjectToDelete = (
235
+ object: any,
236
+ defaultEnvironmentLocaleCode: string
237
+ ) => {
238
+ return (
239
+ !object?.productFields || !object?.slugs?.[defaultEnvironmentLocaleCode]
240
+ );
241
+ };
242
+
235
243
  const getObject = async (
236
244
  topicSubFamily: Entry
237
245
  ): Promise<AlgoliaFamilyRecord> => {
@@ -376,12 +384,13 @@ export const reindexSubFamilies = async (
376
384
  `reindexSubFamilies - offset: ${offset} limit: ${limit} catalog: ${catalogCode}`
377
385
  );
378
386
 
387
+ const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
379
388
  const records = await getObjects(offset, limit, catalogCode);
380
389
  const objectsToSave = records.objects.filter(
381
- (object) => object.productFields
390
+ (object) => !isObjectToDelete(object, defaultEnvironmentLocaleCode)
382
391
  );
383
392
  const objectIdsToDelete = records.objects
384
- .filter((object) => !object?.productFields)
393
+ .filter((object) => isObjectToDelete(object, defaultEnvironmentLocaleCode))
385
394
  .map((object) => object.objectID);
386
395
 
387
396
  // Save records to Algolia
@@ -421,7 +430,8 @@ export const reindexSubFamily = async (topicSubFamilyEntryId: string) => {
421
430
  // Save record to Algolia
422
431
  const index = getIndex(indexKey);
423
432
  let record = null;
424
- if (object.productFields) {
433
+ const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
434
+ if (!isObjectToDelete(object, defaultEnvironmentLocaleCode)) {
425
435
  log(`Save object`);
426
436
  record = await index.saveObject(object);
427
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
@@ -96,6 +96,16 @@ export {
96
96
  reindexStories,
97
97
  removeStoryObject,
98
98
  } from "./algolia/stories";
99
+ export {
100
+ reindexPressReview,
101
+ reindexPressReviews,
102
+ removePressReviewObject,
103
+ } from "./algolia/pressReview";
104
+ export {
105
+ reindexPressRelease,
106
+ reindexPressReleases,
107
+ removePressReleaseObject,
108
+ } from "./algolia/pressRelease";
99
109
  export { importDownloads } from "./downloads/import";
100
110
  export { getLocalISOTime } from "./utils";
101
111
  export { getStaticDailyProducts } from "./pim/endpoints";