pim-import 2.58.1 → 2.60.1
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.
- package/dist/algolia/config.js +36 -0
- package/dist/algolia/config.js.map +1 -1
- package/dist/algolia/downloads.js +3 -2
- package/dist/algolia/downloads.js.map +1 -1
- package/dist/algolia/pipedreamReindex.js +0 -1
- package/dist/algolia/pipedreamReindex.js.map +1 -1
- package/dist/algolia/pressRelease.js +138 -0
- package/dist/algolia/pressRelease.js.map +1 -0
- package/dist/algolia/pressReview.js +140 -0
- package/dist/algolia/pressReview.js.map +1 -0
- package/dist/algolia/subFamilies.js +0 -1
- package/dist/algolia/subFamilies.js.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/libs/contentful.js +8 -1
- package/dist/libs/contentful.js.map +1 -1
- package/dist/pim/methods/products.js +10 -8
- package/dist/pim/methods/products.js.map +1 -1
- package/package.json +1 -1
- package/src/algolia/config.ts +39 -1
- package/src/algolia/downloads.ts +3 -1
- package/src/algolia/pipedreamReindex.ts +0 -1
- package/src/algolia/pressRelease.ts +235 -0
- package/src/algolia/pressReview.ts +228 -0
- package/src/algolia/subFamilies.ts +0 -1
- package/src/index.ts +10 -0
- package/src/libs/contentful.ts +7 -1
- package/src/pim/methods/products.ts +10 -8
|
@@ -0,0 +1,235 @@
|
|
|
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 getObject = async (
|
|
35
|
+
topicPressRelease: Entry
|
|
36
|
+
): Promise<AlgoliaPressReleaseRecord> => {
|
|
37
|
+
const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
38
|
+
log(`Sync the ${topicPressRelease.sys.id} topicPressRelease...`);
|
|
39
|
+
let topicPressReleaseWithFields: Entry = topicPressRelease;
|
|
40
|
+
|
|
41
|
+
if (!topicPressReleaseWithFields?.fields) {
|
|
42
|
+
log(`Get the ${topicPressRelease.sys.id} topicPressRelease details...`);
|
|
43
|
+
topicPressReleaseWithFields = await getEntryByID(
|
|
44
|
+
topicPressRelease.sys.id,
|
|
45
|
+
"topicPressRelease"
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!topicPressReleaseWithFields) {
|
|
50
|
+
log(`The topicPressRelease ${topicPressRelease.sys.id} not found`, "WARN");
|
|
51
|
+
|
|
52
|
+
const recordFail: AlgoliaPressReleaseRecord = {
|
|
53
|
+
objectID: topicPressRelease?.sys?.id,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return recordFail; // return objectID to delete the record if it exists
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
log(`Get thumbnail imgix details...`);
|
|
60
|
+
let thumbnailImgix = {};
|
|
61
|
+
const thumbnailImgixWrapperImgixID =
|
|
62
|
+
topicPressReleaseWithFields?.fields?.thumbnailImgix?.[
|
|
63
|
+
defaultEnvironmentLocaleCode
|
|
64
|
+
]?.sys.id;
|
|
65
|
+
if (thumbnailImgixWrapperImgixID) {
|
|
66
|
+
thumbnailImgix = await getWrapperImgixFields(thumbnailImgixWrapperImgixID);
|
|
67
|
+
} else {
|
|
68
|
+
log(`No thumbnail imgix found`, "WARN");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
log(`Get category details...`);
|
|
72
|
+
const category = await getTopicDetails(
|
|
73
|
+
topicPressReleaseWithFields,
|
|
74
|
+
"category",
|
|
75
|
+
"topicPressReleaseCategory",
|
|
76
|
+
true,
|
|
77
|
+
false,
|
|
78
|
+
false,
|
|
79
|
+
true
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
log(`Get assets details...`);
|
|
83
|
+
let assets: any = [];
|
|
84
|
+
const componentAssets =
|
|
85
|
+
topicPressReleaseWithFields?.fields?.assets?.[defaultEnvironmentLocaleCode];
|
|
86
|
+
if (componentAssets) {
|
|
87
|
+
const componentAssetIds = componentAssets.map(
|
|
88
|
+
(item: CfSys) => item?.sys?.id
|
|
89
|
+
);
|
|
90
|
+
assets = await getAssetsByComponentAssetIds(componentAssetIds);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Single record
|
|
94
|
+
const record: AlgoliaPressReleaseRecord = {
|
|
95
|
+
objectID: topicPressReleaseWithFields.sys.id,
|
|
96
|
+
name: topicPressReleaseWithFields?.fields?.name,
|
|
97
|
+
description: topicPressReleaseWithFields?.fields?.description,
|
|
98
|
+
thumbnailImgix,
|
|
99
|
+
category: category?.[0],
|
|
100
|
+
assets,
|
|
101
|
+
visualizationDate:
|
|
102
|
+
topicPressReleaseWithFields?.fields?.visualizationDate?.[
|
|
103
|
+
defaultEnvironmentLocaleCode
|
|
104
|
+
] || "",
|
|
105
|
+
lastSyncDate: getLocalISOTime(),
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
return record;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export const reindexPressRelease = async (topicPressReleaseId: string) => {
|
|
112
|
+
const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
113
|
+
const timeStart = new Date();
|
|
114
|
+
|
|
115
|
+
log(`reindexPressRelease - entryId: ${topicPressReleaseId} `);
|
|
116
|
+
|
|
117
|
+
const topicPressRelease = await getEntryByID(
|
|
118
|
+
topicPressReleaseId,
|
|
119
|
+
"topicPressRelease"
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
if (!topicPressRelease) {
|
|
123
|
+
log(`No topicPressReleaseId found with id ${topicPressReleaseId}`, "WARN");
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const object = await getObject(topicPressRelease);
|
|
128
|
+
|
|
129
|
+
// Save record to Algolia
|
|
130
|
+
const index = getIndex(indexKey);
|
|
131
|
+
let record = null;
|
|
132
|
+
const names: any = object?.name;
|
|
133
|
+
if (names?.[defaultEnvironmentLocaleCode]) {
|
|
134
|
+
log(`Save object`);
|
|
135
|
+
record = await index.saveObject(object);
|
|
136
|
+
} else {
|
|
137
|
+
log(`Delete object`);
|
|
138
|
+
record = await index.deleteObject(object.objectID);
|
|
139
|
+
}
|
|
140
|
+
const timeEnd = new Date();
|
|
141
|
+
const seconds = secondBetweenTwoDate(timeStart, timeEnd);
|
|
142
|
+
log(`Execution time: ${seconds} seconds`);
|
|
143
|
+
|
|
144
|
+
return { ...record, ...object };
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Get Objects
|
|
149
|
+
*
|
|
150
|
+
* @param offset
|
|
151
|
+
* @param limit
|
|
152
|
+
* @param filterKey
|
|
153
|
+
* @param filterValue
|
|
154
|
+
* @returns
|
|
155
|
+
*/
|
|
156
|
+
const getObjects = async (
|
|
157
|
+
offset: number,
|
|
158
|
+
limit: number,
|
|
159
|
+
filterKey?: string,
|
|
160
|
+
filterValue?: string
|
|
161
|
+
): Promise<AlgoliaPaginateRecords> => {
|
|
162
|
+
const client = await getClient();
|
|
163
|
+
|
|
164
|
+
const opts: any = {
|
|
165
|
+
content_type: "topicPressRelease",
|
|
166
|
+
limit,
|
|
167
|
+
skip: offset,
|
|
168
|
+
locale: "*",
|
|
169
|
+
// select: "",
|
|
170
|
+
};
|
|
171
|
+
if (filterKey && filterValue) {
|
|
172
|
+
opts[filterKey] = filterValue;
|
|
173
|
+
}
|
|
174
|
+
const { items, total } = await client.getEntries(opts);
|
|
175
|
+
|
|
176
|
+
const objects: AlgoliaPressReleaseRecord[] = [];
|
|
177
|
+
let count: number = Number(offset);
|
|
178
|
+
for (const topicPressRelease of items) {
|
|
179
|
+
log(`${++count} of ${total}`, "INFO");
|
|
180
|
+
const timeStart = new Date();
|
|
181
|
+
const record = await getObject(topicPressRelease);
|
|
182
|
+
const timeEnd = new Date();
|
|
183
|
+
const seconds = secondBetweenTwoDate(timeStart, timeEnd);
|
|
184
|
+
log(`Execution time: ${seconds} seconds`);
|
|
185
|
+
objects.push(record);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
objects,
|
|
190
|
+
offset: Number(offset) + Number(limit),
|
|
191
|
+
limit: Number(limit),
|
|
192
|
+
completed: count >= total, // if is true the import is completed
|
|
193
|
+
total,
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
export const reindexPressReleases = async (
|
|
198
|
+
offset: number = 0,
|
|
199
|
+
limit: number = 50,
|
|
200
|
+
filterKey: string = "",
|
|
201
|
+
filterValue: string = ""
|
|
202
|
+
) => {
|
|
203
|
+
const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
204
|
+
const timeStart = new Date();
|
|
205
|
+
log(
|
|
206
|
+
`reindexPressReleases - filterKey: ${filterKey} filterValue: ${filterValue} offset: ${offset} limit: ${limit} `
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
const records = await getObjects(offset, limit, filterKey, filterValue);
|
|
210
|
+
const objectsToSave = records.objects.filter(
|
|
211
|
+
(object) => object?.name?.[defaultEnvironmentLocaleCode]
|
|
212
|
+
);
|
|
213
|
+
const objectIdsToDelete = records.objects
|
|
214
|
+
.filter((object) => !object?.name?.[defaultEnvironmentLocaleCode])
|
|
215
|
+
.map((object) => object.objectID);
|
|
216
|
+
|
|
217
|
+
// Save records to Algolia
|
|
218
|
+
const index = getIndex(indexKey);
|
|
219
|
+
log(`Save ${objectsToSave.length} objects to ${index.indexName} index`);
|
|
220
|
+
const savedObjectIDs = await index.saveObjects(objectsToSave);
|
|
221
|
+
log(
|
|
222
|
+
`Delete ${objectIdsToDelete.length} objects from ${index.indexName} index`
|
|
223
|
+
);
|
|
224
|
+
const deletedObjectIDs = await index.deleteObjects(objectIdsToDelete);
|
|
225
|
+
|
|
226
|
+
const timeEnd = new Date();
|
|
227
|
+
const seconds = secondBetweenTwoDate(timeStart, timeEnd);
|
|
228
|
+
log(`Execution time: ${seconds} seconds`);
|
|
229
|
+
|
|
230
|
+
return { ...records, ...savedObjectIDs, ...deletedObjectIDs };
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
export const removePressReleaseObject = async (objectId: string) => {
|
|
234
|
+
return removeIndexObject(objectId, indexKey);
|
|
235
|
+
};
|
|
@@ -0,0 +1,228 @@
|
|
|
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 getObject = async (
|
|
32
|
+
topicPressReview: Entry
|
|
33
|
+
): Promise<AlgoliaPressReviewRecord> => {
|
|
34
|
+
const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
35
|
+
log(`Sync the ${topicPressReview.sys.id} topicPressReview...`);
|
|
36
|
+
let topicPressReviewWithFields: Entry = topicPressReview;
|
|
37
|
+
|
|
38
|
+
if (!topicPressReviewWithFields?.fields) {
|
|
39
|
+
log(`Get the ${topicPressReview.sys.id} topicPressReview details...`);
|
|
40
|
+
topicPressReviewWithFields = await getEntryByID(
|
|
41
|
+
topicPressReview.sys.id,
|
|
42
|
+
"topicPressReview"
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (!topicPressReviewWithFields) {
|
|
47
|
+
log(`The topicPressReview ${topicPressReview.sys.id} not found`, "WARN");
|
|
48
|
+
|
|
49
|
+
const recordFail: AlgoliaPressReviewRecord = {
|
|
50
|
+
objectID: topicPressReview?.sys?.id,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
return recordFail; // return objectID to delete the record if it exists
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
log(`Get thumbnail imgix details...`);
|
|
57
|
+
let thumbnailImgix = {};
|
|
58
|
+
const thumbnailImgixWrapperImgixID =
|
|
59
|
+
topicPressReviewWithFields?.fields?.thumbnailImageImgix?.[
|
|
60
|
+
defaultEnvironmentLocaleCode
|
|
61
|
+
]?.sys.id;
|
|
62
|
+
if (thumbnailImgixWrapperImgixID) {
|
|
63
|
+
thumbnailImgix = await getWrapperImgixFields(thumbnailImgixWrapperImgixID);
|
|
64
|
+
} else {
|
|
65
|
+
log(`No thumbnail imgix found`, "WARN");
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
log(`Get asset details...`);
|
|
69
|
+
const fileId =
|
|
70
|
+
topicPressReviewWithFields?.fields?.asset?.[defaultEnvironmentLocaleCode]
|
|
71
|
+
?.sys?.id;
|
|
72
|
+
let asset = {};
|
|
73
|
+
if (fileId) {
|
|
74
|
+
const componentAssetIds = await getAssetsByComponentAssetIds([fileId]);
|
|
75
|
+
asset = componentAssetIds ? componentAssetIds[0] : {};
|
|
76
|
+
} else {
|
|
77
|
+
log(`No asset found`, "WARN");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Single record
|
|
81
|
+
const record: AlgoliaPressReviewRecord = {
|
|
82
|
+
objectID: topicPressReviewWithFields.sys.id,
|
|
83
|
+
name: topicPressReviewWithFields?.fields?.name,
|
|
84
|
+
yearOfRelease:
|
|
85
|
+
topicPressReviewWithFields?.fields?.yearOfRelease?.[
|
|
86
|
+
defaultEnvironmentLocaleCode
|
|
87
|
+
] || "",
|
|
88
|
+
monthOfRelease:
|
|
89
|
+
topicPressReviewWithFields?.fields?.monthOfRelease?.[
|
|
90
|
+
defaultEnvironmentLocaleCode
|
|
91
|
+
] || "",
|
|
92
|
+
country:
|
|
93
|
+
topicPressReviewWithFields?.fields?.country?.[
|
|
94
|
+
defaultEnvironmentLocaleCode
|
|
95
|
+
] || "",
|
|
96
|
+
thumbnailImgix,
|
|
97
|
+
asset,
|
|
98
|
+
lastSyncDate: getLocalISOTime(),
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return record;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const reindexPressReview = async (topicPressReviewId: string) => {
|
|
105
|
+
const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
106
|
+
const timeStart = new Date();
|
|
107
|
+
|
|
108
|
+
log(`reindexPressReview - entryId: ${topicPressReviewId} `);
|
|
109
|
+
|
|
110
|
+
const topicPressReview = await getEntryByID(
|
|
111
|
+
topicPressReviewId,
|
|
112
|
+
"topicPressReview"
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
if (!topicPressReview) {
|
|
116
|
+
log(`No topicPressReviewId found with id ${topicPressReviewId}`, "WARN");
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const object = await getObject(topicPressReview);
|
|
121
|
+
|
|
122
|
+
// Save record to Algolia
|
|
123
|
+
const index = getIndex(indexKey);
|
|
124
|
+
let record = null;
|
|
125
|
+
const names: any = object?.name;
|
|
126
|
+
if (names?.[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: "topicPressReview",
|
|
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: AlgoliaPressReviewRecord[] = [];
|
|
170
|
+
let count: number = Number(offset);
|
|
171
|
+
for (const topicPressReview of items) {
|
|
172
|
+
log(`${++count} of ${total}`, "INFO");
|
|
173
|
+
const timeStart = new Date();
|
|
174
|
+
const record = await getObject(topicPressReview);
|
|
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 reindexPressReviews = 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
|
+
`reindexPressReviews - 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) => object?.name?.[defaultEnvironmentLocaleCode]
|
|
205
|
+
);
|
|
206
|
+
const objectIdsToDelete = records.objects
|
|
207
|
+
.filter((object) => !object?.name?.[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 removePressReviewObject = async (objectId: string) => {
|
|
227
|
+
return removeIndexObject(objectId, indexKey);
|
|
228
|
+
};
|
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";
|
package/src/libs/contentful.ts
CHANGED
|
@@ -1318,7 +1318,13 @@ export const archiveEntry = async (
|
|
|
1318
1318
|
entry = await entry.archive();
|
|
1319
1319
|
|
|
1320
1320
|
if (isProduct) {
|
|
1321
|
-
await
|
|
1321
|
+
const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
1322
|
+
const recordObjectId = entry.fields.code[defEnvLocaleCode];
|
|
1323
|
+
if (recordObjectId) {
|
|
1324
|
+
await removeProductObject(recordObjectId);
|
|
1325
|
+
} else {
|
|
1326
|
+
log(`recordObjectId not found`, "WARN");
|
|
1327
|
+
}
|
|
1322
1328
|
}
|
|
1323
1329
|
} else {
|
|
1324
1330
|
log(`Entry ${entry.sys.id} is already archived`);
|
|
@@ -1494,6 +1494,8 @@ export const audit = async (
|
|
|
1494
1494
|
limit: number = 150,
|
|
1495
1495
|
s3FilePath: string = ""
|
|
1496
1496
|
) => {
|
|
1497
|
+
offset = Number(offset);
|
|
1498
|
+
limit = Number(limit);
|
|
1497
1499
|
const timeStart = new Date();
|
|
1498
1500
|
log(`audit - lastModified: ${lastModified} catalog: ${catalog}`, "INFO");
|
|
1499
1501
|
|
|
@@ -1503,8 +1505,8 @@ export const audit = async (
|
|
|
1503
1505
|
if (!allAudit) {
|
|
1504
1506
|
log(`No audits were found to process for the date ${lastModified}`);
|
|
1505
1507
|
return {
|
|
1506
|
-
offset
|
|
1507
|
-
limit
|
|
1508
|
+
offset,
|
|
1509
|
+
limit,
|
|
1508
1510
|
completed: true,
|
|
1509
1511
|
s3FilePath: "",
|
|
1510
1512
|
total: 0,
|
|
@@ -1555,7 +1557,7 @@ export const audit = async (
|
|
|
1555
1557
|
log(
|
|
1556
1558
|
`No products found between offset: ${offset} and limit: ${limit}. Total: ${total}`
|
|
1557
1559
|
);
|
|
1558
|
-
const nextOffset =
|
|
1560
|
+
const nextOffset = offset + limit;
|
|
1559
1561
|
const completed = limit === -1 || nextOffset >= total;
|
|
1560
1562
|
if (completed) {
|
|
1561
1563
|
log(`Audit completed`);
|
|
@@ -1567,7 +1569,7 @@ export const audit = async (
|
|
|
1567
1569
|
|
|
1568
1570
|
return {
|
|
1569
1571
|
offset: nextOffset,
|
|
1570
|
-
limit:
|
|
1572
|
+
limit: limit,
|
|
1571
1573
|
completed,
|
|
1572
1574
|
s3FilePath,
|
|
1573
1575
|
total,
|
|
@@ -1680,7 +1682,7 @@ export const audit = async (
|
|
|
1680
1682
|
}
|
|
1681
1683
|
}
|
|
1682
1684
|
|
|
1683
|
-
const nextOffset =
|
|
1685
|
+
const nextOffset = offset + limit;
|
|
1684
1686
|
|
|
1685
1687
|
const tEnd = new Date();
|
|
1686
1688
|
const secs = secondBetweenTwoDate(timeStart, tEnd);
|
|
@@ -1688,7 +1690,7 @@ export const audit = async (
|
|
|
1688
1690
|
|
|
1689
1691
|
return {
|
|
1690
1692
|
offset: nextOffset,
|
|
1691
|
-
limit
|
|
1693
|
+
limit,
|
|
1692
1694
|
completed: limit === -1 || count >= total,
|
|
1693
1695
|
s3FilePath,
|
|
1694
1696
|
total,
|
|
@@ -1701,8 +1703,8 @@ export const audit = async (
|
|
|
1701
1703
|
log(`Request time: ${secs} seconds`);
|
|
1702
1704
|
|
|
1703
1705
|
return {
|
|
1704
|
-
offset:
|
|
1705
|
-
limit:
|
|
1706
|
+
offset: offset,
|
|
1707
|
+
limit: limit,
|
|
1706
1708
|
completed: true,
|
|
1707
1709
|
s3FilePath,
|
|
1708
1710
|
};
|