pim-import 2.4.2 → 2.5.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.
- package/dist/algolia/collections.js +23 -33
- package/dist/algolia/collections.js.map +1 -1
- package/dist/algolia/config.js +2 -0
- package/dist/algolia/config.js.map +1 -1
- package/dist/algolia/models.js +13 -26
- package/dist/algolia/models.js.map +1 -1
- package/dist/algolia/products.js +34 -58
- package/dist/algolia/products.js.map +1 -1
- package/dist/algolia/subModels.js +15 -23
- package/dist/algolia/subModels.js.map +1 -1
- package/dist/libs/contenful-cda.js +254 -0
- package/dist/libs/contenful-cda.js.map +1 -0
- package/dist/pim/methods/models.js +1 -1
- package/dist/pim/methods/models.js.map +1 -1
- package/dist/pim/methods/subfamilies.js +19 -1
- package/dist/pim/methods/subfamilies.js.map +1 -1
- package/package.json +2 -1
- package/src/algolia/collections.ts +11 -68
- package/src/algolia/config.ts +2 -0
- package/src/algolia/models.ts +12 -27
- package/src/algolia/products.ts +9 -39
- package/src/algolia/subModels.ts +8 -28
- package/src/libs/contenful-cda.ts +445 -0
- package/src/pim/methods/models.ts +1 -1
- package/src/pim/methods/subfamilies.ts +26 -1
- package/src/types.ts +23 -0
|
@@ -1,53 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* Esempio singolo record
|
|
5
|
-
* - topicFamily Name
|
|
6
|
-
* - topicFamily Thumbnail URL
|
|
7
|
-
* - topicFamily Page URL
|
|
8
|
-
* - topicFamily Catalogs
|
|
9
|
-
* - topicFamily Categories
|
|
10
|
-
* -- topicCategory Name
|
|
11
|
-
* -- topicCategory Link a pagina
|
|
12
|
-
* - topicProduct certification enec
|
|
13
|
-
* - topicProduct certification ul
|
|
14
|
-
* - topicProduct mounting
|
|
15
|
-
* - topicProduct orientation
|
|
16
|
-
* - topicProduct driver type
|
|
17
|
-
* - topicProduct lighting distribution
|
|
18
|
-
* - topicProduct optical type
|
|
19
|
-
* - topicProduct markets
|
|
20
|
-
* - topicProduct statusLabel
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* LOGICA
|
|
24
|
-
* 1. Ottenere tutti i topicFamily
|
|
25
|
-
* 2. Per ogni topicFamily:
|
|
26
|
-
* 2.1 name - topicFamily Name
|
|
27
|
-
* 2.2 thumbnail - topicFamily Thumbnail URL
|
|
28
|
-
* 2.3 pageUrl - topicFamily Page URL (Se all’interno di una family c’è solo una subFamily manda alla subFamily, se all’interno della subFamily a sua volta c’è un solo model manda direttamente al model (cambia solo il link alla pagina gli altri dati sono sempre presi dalla family)
|
|
29
|
-
* 2.4 catalogs - topicFamily Catalogs [FACET]
|
|
30
|
-
* 2.5 categories - topicFamily Categories [FACET]
|
|
31
|
-
* 2.6 Tutti i prodotti associati alla famiglia [teoricamente dovremmo prendere solo i prodotti pubblicati e con status published ma al momento no ne avremo](È CORRETTO PRENDERE TUTTI I PRODOTTI ASSOCIATI ALLA FAMIGLIA O POSSONO ESSERCI DEI PRODOTTI DELLA STESSA FAMIGLIA CHE APPARTENGONO A CATALOGHI DIVERSI?)
|
|
32
|
-
* 2.7 Per ogni prodotto ottenere i campi prodotti da utilizzare per i filtri di pagina:
|
|
33
|
-
* 2.7.1 productFields->certification->enec - topicProduct certification enec
|
|
34
|
-
* 2.7.2 productFields->certification->ul topicProduct certification ul
|
|
35
|
-
* 2.7.3 productFields->mountings - topicProduct mounting
|
|
36
|
-
* 2.7.4 productFields->orintations - topicProduct orientation
|
|
37
|
-
* 2.7.5 productFields->driverTypes - topicProduct driver type
|
|
38
|
-
* 2.7.6 productFields->lightingDistributions - topicProduct lighting distribution
|
|
39
|
-
* 2.7.7 productFields->opticalType - topicProduct optical type
|
|
40
|
-
* 2.7.8 productFields->markets - topicProduct markets
|
|
41
|
-
* 2.8 statusLabel - (boolean) se almeno un prodotto ha il campo upgrade = UP3
|
|
2
|
+
* Collection index
|
|
42
3
|
*/
|
|
43
4
|
import {
|
|
44
|
-
|
|
45
|
-
getEntryByID,
|
|
5
|
+
getClient,
|
|
46
6
|
getEnvironmentDefaultLocaleCode,
|
|
47
|
-
|
|
7
|
+
getEntryByID,
|
|
8
|
+
getAllEntries,
|
|
48
9
|
getTopicDetails,
|
|
49
10
|
getAssetDetails,
|
|
50
|
-
} from "../libs/
|
|
11
|
+
} from "../libs/contenful-cda";
|
|
51
12
|
import {
|
|
52
13
|
CfLocalizedEntryField,
|
|
53
14
|
TopicDetailsResponse,
|
|
@@ -65,7 +26,6 @@ import {
|
|
|
65
26
|
secondBetweenTwoDate,
|
|
66
27
|
keysToLowerCase,
|
|
67
28
|
addProductFieldValueCodesByPimDetails,
|
|
68
|
-
sleep,
|
|
69
29
|
} from "../utils";
|
|
70
30
|
import { getSubFamilyPageSlugWithDetails } from "../pim/methods/subfamilies";
|
|
71
31
|
|
|
@@ -96,7 +56,6 @@ const indexKey: AvailableIndicesKey = "collections";
|
|
|
96
56
|
|
|
97
57
|
const getFamilyPage = async (topicFamily: Entry): Promise<pageResponse> => {
|
|
98
58
|
const defaultEnvironmentLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
99
|
-
const env = await getEnvironment();
|
|
100
59
|
const familyPage = await getEntryByID(`${topicFamily.sys.id}_PAGE`, "page");
|
|
101
60
|
|
|
102
61
|
// check if family page has many relations with subFamily pages
|
|
@@ -119,11 +78,12 @@ const getFamilyPage = async (topicFamily: Entry): Promise<pageResponse> => {
|
|
|
119
78
|
const subFamilyPageId = subFamilyPageIds[0];
|
|
120
79
|
|
|
121
80
|
// check if subFamily has many relations with model
|
|
122
|
-
const
|
|
81
|
+
const client = await getClient();
|
|
82
|
+
const { items: modelEntries } = await client.getEntries({
|
|
123
83
|
content_type: "topicModel",
|
|
124
84
|
"fields.subFamily.sys.id": subFamilyPageId.replace("_PAGE", ""),
|
|
125
85
|
limit: 2,
|
|
126
|
-
locale:
|
|
86
|
+
locale: "*",
|
|
127
87
|
select: "sys,fields.catalog,fields.subFamily",
|
|
128
88
|
});
|
|
129
89
|
|
|
@@ -310,8 +270,6 @@ const getObject = async (topicFamily: Entry): Promise<AlgoliaFamilyRecord> => {
|
|
|
310
270
|
const page = await getFamilyPage(topicFamilyWithFields);
|
|
311
271
|
log(`Slugs type: ${page?.type}`);
|
|
312
272
|
|
|
313
|
-
await sleep(200, true);
|
|
314
|
-
|
|
315
273
|
log(`Get catalogs details...`);
|
|
316
274
|
const catalogs = await getTopicDetails(
|
|
317
275
|
topicFamilyWithFields,
|
|
@@ -321,8 +279,6 @@ const getObject = async (topicFamily: Entry): Promise<AlgoliaFamilyRecord> => {
|
|
|
321
279
|
);
|
|
322
280
|
log(`${catalogs?.length} catalogs founded`);
|
|
323
281
|
|
|
324
|
-
await sleep(200, true);
|
|
325
|
-
|
|
326
282
|
log(`Get categories details...`);
|
|
327
283
|
const categories = await getTopicDetails(
|
|
328
284
|
topicFamilyWithFields,
|
|
@@ -332,13 +288,9 @@ const getObject = async (topicFamily: Entry): Promise<AlgoliaFamilyRecord> => {
|
|
|
332
288
|
);
|
|
333
289
|
log(`${categories?.length} categories founded`);
|
|
334
290
|
|
|
335
|
-
await sleep(200, true);
|
|
336
|
-
|
|
337
291
|
log(`Get productFields details...`);
|
|
338
292
|
const productFields = await getProductFields(topicFamily);
|
|
339
293
|
|
|
340
|
-
await sleep(200, true);
|
|
341
|
-
|
|
342
294
|
const isNew: boolean = !!productFields?.upgrade?.find(
|
|
343
295
|
(item: any) => item === "UP3"
|
|
344
296
|
);
|
|
@@ -349,8 +301,6 @@ const getObject = async (topicFamily: Entry): Promise<AlgoliaFamilyRecord> => {
|
|
|
349
301
|
?.sys?.id;
|
|
350
302
|
const thumbnail = thumbnailID ? await getAssetDetails(thumbnailID) : {};
|
|
351
303
|
|
|
352
|
-
await sleep(200, true);
|
|
353
|
-
|
|
354
304
|
log(`Get full screen details...`);
|
|
355
305
|
const fullScreenImageID =
|
|
356
306
|
topicFamilyWithFields?.fields?.fullScreenImage?.[
|
|
@@ -360,8 +310,6 @@ const getObject = async (topicFamily: Entry): Promise<AlgoliaFamilyRecord> => {
|
|
|
360
310
|
? await getAssetDetails(fullScreenImageID)
|
|
361
311
|
: {};
|
|
362
312
|
|
|
363
|
-
await sleep(200, true);
|
|
364
|
-
|
|
365
313
|
log(`Get priority details...`);
|
|
366
314
|
const priority =
|
|
367
315
|
topicFamilyWithFields?.fields?.priority?.[defaultEnvironmentLocaleCode] ||
|
|
@@ -393,17 +341,16 @@ const getObjects = async (
|
|
|
393
341
|
offset: number,
|
|
394
342
|
limit: number
|
|
395
343
|
): Promise<AlgoliaPaginateRecords> => {
|
|
396
|
-
const
|
|
397
|
-
const env = await getEnvironment();
|
|
344
|
+
const client = await getClient();
|
|
398
345
|
|
|
399
346
|
const opts: any = {
|
|
400
347
|
content_type: "topicFamily",
|
|
401
348
|
limit,
|
|
402
349
|
skip: offset,
|
|
403
|
-
locale:
|
|
350
|
+
locale: "*",
|
|
404
351
|
select: "sys",
|
|
405
352
|
};
|
|
406
|
-
const { items, total } = await
|
|
353
|
+
const { items, total } = await client.getEntries(opts);
|
|
407
354
|
|
|
408
355
|
const objects: AlgoliaFamilyRecord[] = [];
|
|
409
356
|
let count: number = Number(offset);
|
|
@@ -415,10 +362,6 @@ const getObjects = async (
|
|
|
415
362
|
const seconds = secondBetweenTwoDate(timeStart, timeEnd);
|
|
416
363
|
log(`Execution time: ${seconds} seconds`);
|
|
417
364
|
objects.push(record);
|
|
418
|
-
|
|
419
|
-
if (count % 7 === 0) {
|
|
420
|
-
await sleep(2000, true);
|
|
421
|
-
}
|
|
422
365
|
}
|
|
423
366
|
|
|
424
367
|
return {
|
package/src/algolia/config.ts
CHANGED
|
@@ -57,6 +57,8 @@ export const getIndicesSettings = () => {
|
|
|
57
57
|
"productFields.applications.code",
|
|
58
58
|
"productFields.photometric.temperatureColor.code",
|
|
59
59
|
"productFields.optical.numberOfHeads",
|
|
60
|
+
"productFields.physical.length",
|
|
61
|
+
"productFields.electrical.powerSupplyType.code",
|
|
60
62
|
],
|
|
61
63
|
searchableAttributes: ["name", "code"],
|
|
62
64
|
},
|
package/src/algolia/models.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
2
|
* Model index
|
|
4
|
-
*
|
|
5
3
|
*/
|
|
6
4
|
import {
|
|
7
|
-
|
|
8
|
-
getEntryByID,
|
|
5
|
+
getClient,
|
|
9
6
|
getEnvironmentDefaultLocaleCode,
|
|
10
|
-
|
|
11
|
-
getEntryImageDetails,
|
|
12
|
-
getTopicDetails,
|
|
7
|
+
getEntryByID,
|
|
13
8
|
getAllEntries,
|
|
14
|
-
|
|
9
|
+
getTopicDetails,
|
|
10
|
+
getEntryImageDetails,
|
|
11
|
+
} from "../libs/contenful-cda";
|
|
15
12
|
import {
|
|
16
13
|
CfLocalizedEntryField,
|
|
17
14
|
TopicDetailsResponse,
|
|
@@ -26,7 +23,6 @@ import {
|
|
|
26
23
|
secondBetweenTwoDate,
|
|
27
24
|
capitalizeFirstLetter,
|
|
28
25
|
keysToLowerCase,
|
|
29
|
-
sleep,
|
|
30
26
|
} from "../utils";
|
|
31
27
|
|
|
32
28
|
const indexKey: AvailableIndicesKey = "models";
|
|
@@ -119,8 +115,10 @@ const getModelAutodescription = async (productLineCode: string) => {
|
|
|
119
115
|
// // Profile and others
|
|
120
116
|
// break;
|
|
121
117
|
// }
|
|
122
|
-
|
|
123
|
-
return
|
|
118
|
+
|
|
119
|
+
return (
|
|
120
|
+
"TODO: definire autodescription model. ProductLine: " + productLineCode
|
|
121
|
+
);
|
|
124
122
|
};
|
|
125
123
|
|
|
126
124
|
const getObject = async (
|
|
@@ -140,7 +138,6 @@ const getObject = async (
|
|
|
140
138
|
log(`The topicModel with id ${topicModelId} not found`, "WARN");
|
|
141
139
|
return { objectID: topicModelId };
|
|
142
140
|
}
|
|
143
|
-
await sleep(200, true);
|
|
144
141
|
|
|
145
142
|
log(`Get model page details...`);
|
|
146
143
|
const modelPageId = `${topicModelId}_PAGE`;
|
|
@@ -150,7 +147,6 @@ const getObject = async (
|
|
|
150
147
|
"fields.slug,fields.type"
|
|
151
148
|
);
|
|
152
149
|
const slugs = modelPage?.fields?.slug;
|
|
153
|
-
await sleep(200, true);
|
|
154
150
|
|
|
155
151
|
log(`Get catalog details...`);
|
|
156
152
|
const catalogs = await getTopicDetails(
|
|
@@ -167,7 +163,6 @@ const getObject = async (
|
|
|
167
163
|
"WARN"
|
|
168
164
|
);
|
|
169
165
|
}
|
|
170
|
-
await sleep(200, true);
|
|
171
166
|
|
|
172
167
|
log(`Get productLine details...`);
|
|
173
168
|
const productLines = await getTopicDetails(
|
|
@@ -177,7 +172,6 @@ const getObject = async (
|
|
|
177
172
|
true
|
|
178
173
|
);
|
|
179
174
|
const productLine = productLines?.[0];
|
|
180
|
-
await sleep(200, true);
|
|
181
175
|
|
|
182
176
|
log(`Get subFamily details...`);
|
|
183
177
|
const subFamilies = await getTopicDetails(
|
|
@@ -187,14 +181,12 @@ const getObject = async (
|
|
|
187
181
|
true
|
|
188
182
|
);
|
|
189
183
|
const subFamily = subFamilies?.[0];
|
|
190
|
-
await sleep(200, true);
|
|
191
184
|
|
|
192
185
|
log(`Get thumbnail details...`);
|
|
193
186
|
const thumbnail = await getEntryImageDetails(
|
|
194
187
|
topicModelWithFields,
|
|
195
188
|
"thumbnail"
|
|
196
189
|
);
|
|
197
|
-
await sleep(200, true);
|
|
198
190
|
|
|
199
191
|
log(`Get colors details...`);
|
|
200
192
|
const colors: string[] = [];
|
|
@@ -213,14 +205,12 @@ const getObject = async (
|
|
|
213
205
|
colors.push(productColor);
|
|
214
206
|
}
|
|
215
207
|
});
|
|
216
|
-
await sleep(200, true);
|
|
217
208
|
} else {
|
|
218
209
|
log(`I cannot get the colors because there is no catalog`, "WARN");
|
|
219
210
|
}
|
|
220
211
|
|
|
221
212
|
log(`Get autodescription details...`);
|
|
222
213
|
const autodescription = await getModelAutodescription(productLine.code);
|
|
223
|
-
await sleep(200, true);
|
|
224
214
|
|
|
225
215
|
/*
|
|
226
216
|
|
|
@@ -297,20 +287,19 @@ const getObjects = async (
|
|
|
297
287
|
limit: number,
|
|
298
288
|
catalogCode?: AvailableCatalogs
|
|
299
289
|
): Promise<AlgoliaPaginateRecords> => {
|
|
300
|
-
const
|
|
301
|
-
const env = await getEnvironment();
|
|
290
|
+
const client = await getClient();
|
|
302
291
|
|
|
303
292
|
const opts: any = {
|
|
304
293
|
content_type: "topicModel",
|
|
305
294
|
limit,
|
|
306
295
|
skip: offset,
|
|
307
|
-
locale:
|
|
296
|
+
locale: "*",
|
|
308
297
|
select: topicModelSelect,
|
|
309
298
|
};
|
|
310
299
|
if (catalogCode) {
|
|
311
300
|
opts["fields.catalog.sys.id"] = catalogCode;
|
|
312
301
|
}
|
|
313
|
-
const { items, total } = await
|
|
302
|
+
const { items, total } = await client.getEntries(opts);
|
|
314
303
|
|
|
315
304
|
const objects: AlgoliaModelRecord[] = [];
|
|
316
305
|
let count: number = Number(offset);
|
|
@@ -322,10 +311,6 @@ const getObjects = async (
|
|
|
322
311
|
const seconds = secondBetweenTwoDate(timeStart, timeEnd);
|
|
323
312
|
log(`Execution time: ${seconds} seconds`);
|
|
324
313
|
objects.push(record);
|
|
325
|
-
|
|
326
|
-
if (count % 7 === 0) {
|
|
327
|
-
await sleep(2000, true);
|
|
328
|
-
}
|
|
329
314
|
}
|
|
330
315
|
|
|
331
316
|
return {
|
package/src/algolia/products.ts
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Product index
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* TODO: Add thumbnail
|
|
6
3
|
*/
|
|
4
|
+
import { cfLocales } from "../libs/contentful";
|
|
7
5
|
import {
|
|
8
|
-
|
|
6
|
+
getClient,
|
|
9
7
|
getEnvironmentDefaultLocaleCode,
|
|
8
|
+
getEntryByID,
|
|
10
9
|
getTopicDetails,
|
|
11
|
-
getEnvironment,
|
|
12
|
-
getDictionaryLocaleValue,
|
|
13
|
-
cfLocales,
|
|
14
10
|
getDictionaryJson,
|
|
11
|
+
getDictionaryLocaleValue,
|
|
15
12
|
getEntryImageDetails,
|
|
16
|
-
} from "../libs/
|
|
13
|
+
} from "../libs/contenful-cda";
|
|
17
14
|
import {
|
|
18
15
|
CfLocalizedEntryField,
|
|
19
16
|
TopicDetailsResponse,
|
|
@@ -28,7 +25,6 @@ import {
|
|
|
28
25
|
getLocalISOTime,
|
|
29
26
|
secondBetweenTwoDate,
|
|
30
27
|
keysToLowerCase,
|
|
31
|
-
sleep,
|
|
32
28
|
} from "../utils";
|
|
33
29
|
|
|
34
30
|
export type AlgoliaProductRecord = {
|
|
@@ -65,7 +61,7 @@ export type AlgoliaProductRecord = {
|
|
|
65
61
|
|
|
66
62
|
const indexKey: AvailableIndicesKey = "products";
|
|
67
63
|
const topicProductSelect =
|
|
68
|
-
"sys,fields.name,fields.code,fields.catalogs,fields.categoriesArchitectural,fields.categoriesOutdoor,fields.categoriesDecorative,fields.families,fields.subFamiliesArchitectural,fields.subFamiliesOutdoor,fields.subFamiliesDecorative,fields.modelsArchitectural,fields.modelsOutdoor,fields.modelsDecorative,fields.subModelsArchitectural,fields.subModelsOutdoor,fields.subModelsDecorative,fields.productLine,fields.productFields";
|
|
64
|
+
"sys,fields.name,fields.code,fields.catalogs,fields.categoriesArchitectural,fields.categoriesOutdoor,fields.categoriesDecorative,fields.families,fields.subFamiliesArchitectural,fields.subFamiliesOutdoor,fields.subFamiliesDecorative,fields.modelsArchitectural,fields.modelsOutdoor,fields.modelsDecorative,fields.subModelsArchitectural,fields.subModelsOutdoor,fields.subModelsDecorative,fields.productLine,fields.productSubLine,fields.productFields";
|
|
69
65
|
|
|
70
66
|
const getLightModuleAutoDescriptionByProductFields = async (
|
|
71
67
|
productFileds: any,
|
|
@@ -290,7 +286,6 @@ const getObject = async (
|
|
|
290
286
|
topicProductSelect
|
|
291
287
|
);
|
|
292
288
|
}
|
|
293
|
-
await sleep(200, true);
|
|
294
289
|
|
|
295
290
|
if (!topicProductWithFields) {
|
|
296
291
|
log(`The topicProduct ${topicProduct.sys.id} not found`, "WARN");
|
|
@@ -308,7 +303,6 @@ const getObject = async (
|
|
|
308
303
|
"page",
|
|
309
304
|
"sys,fields.slug"
|
|
310
305
|
);
|
|
311
|
-
await sleep(200, true);
|
|
312
306
|
|
|
313
307
|
const slugs = keysToLowerCase(productPage?.fields?.slug) || {};
|
|
314
308
|
|
|
@@ -319,7 +313,6 @@ const getObject = async (
|
|
|
319
313
|
"topicCatalog",
|
|
320
314
|
true
|
|
321
315
|
);
|
|
322
|
-
await sleep(200, true);
|
|
323
316
|
|
|
324
317
|
log(`Get categoriesArchitectural details...`);
|
|
325
318
|
const categoriesArchitectural = await getTopicDetails(
|
|
@@ -328,7 +321,6 @@ const getObject = async (
|
|
|
328
321
|
"topicCategory",
|
|
329
322
|
true
|
|
330
323
|
);
|
|
331
|
-
await sleep(200, true);
|
|
332
324
|
|
|
333
325
|
log(`Get categoriesOutdoor details...`);
|
|
334
326
|
const categoriesOutdoor = await getTopicDetails(
|
|
@@ -337,7 +329,6 @@ const getObject = async (
|
|
|
337
329
|
"topicCategory",
|
|
338
330
|
true
|
|
339
331
|
);
|
|
340
|
-
await sleep(200, true);
|
|
341
332
|
|
|
342
333
|
log(`Get categoriesDecorative details...`);
|
|
343
334
|
const categoriesDecorative = await getTopicDetails(
|
|
@@ -346,7 +337,6 @@ const getObject = async (
|
|
|
346
337
|
"topicCategory",
|
|
347
338
|
true
|
|
348
339
|
);
|
|
349
|
-
await sleep(200, true);
|
|
350
340
|
|
|
351
341
|
log(`Get families details...`);
|
|
352
342
|
const families = await getTopicDetails(
|
|
@@ -355,7 +345,6 @@ const getObject = async (
|
|
|
355
345
|
"topicFamily",
|
|
356
346
|
true
|
|
357
347
|
);
|
|
358
|
-
await sleep(200, true);
|
|
359
348
|
|
|
360
349
|
log(`Get subFamiliesArchitectural details...`);
|
|
361
350
|
const subFamiliesArchitectural = await getTopicDetails(
|
|
@@ -365,7 +354,6 @@ const getObject = async (
|
|
|
365
354
|
true,
|
|
366
355
|
true
|
|
367
356
|
);
|
|
368
|
-
await sleep(200, true);
|
|
369
357
|
|
|
370
358
|
log(`Get subFamiliesOutdoor details...`);
|
|
371
359
|
const subFamiliesOutdoor = await getTopicDetails(
|
|
@@ -375,7 +363,6 @@ const getObject = async (
|
|
|
375
363
|
true,
|
|
376
364
|
true
|
|
377
365
|
);
|
|
378
|
-
await sleep(200, true);
|
|
379
366
|
|
|
380
367
|
log(`Get subFamiliesDecorative details...`);
|
|
381
368
|
const subFamiliesDecorative = await getTopicDetails(
|
|
@@ -385,7 +372,6 @@ const getObject = async (
|
|
|
385
372
|
true,
|
|
386
373
|
true
|
|
387
374
|
);
|
|
388
|
-
await sleep(200, true);
|
|
389
375
|
|
|
390
376
|
log(`Get modelsArchitectural details...`);
|
|
391
377
|
const modelsArchitectural = await getTopicDetails(
|
|
@@ -394,7 +380,6 @@ const getObject = async (
|
|
|
394
380
|
"topicModel",
|
|
395
381
|
true
|
|
396
382
|
);
|
|
397
|
-
await sleep(200, true);
|
|
398
383
|
|
|
399
384
|
log(`Get modelsOutdoor details...`);
|
|
400
385
|
const modelsOutdoor = await getTopicDetails(
|
|
@@ -403,7 +388,6 @@ const getObject = async (
|
|
|
403
388
|
"topicModel",
|
|
404
389
|
true
|
|
405
390
|
);
|
|
406
|
-
await sleep(200, true);
|
|
407
391
|
|
|
408
392
|
log(`Get modelsDecorative details...`);
|
|
409
393
|
const modelsDecorative = await getTopicDetails(
|
|
@@ -412,7 +396,6 @@ const getObject = async (
|
|
|
412
396
|
"topicModel",
|
|
413
397
|
true
|
|
414
398
|
);
|
|
415
|
-
await sleep(200, true);
|
|
416
399
|
|
|
417
400
|
log(`Get subModelsArchitectural details...`);
|
|
418
401
|
const subModelsArchitectural = await getTopicDetails(
|
|
@@ -421,7 +404,6 @@ const getObject = async (
|
|
|
421
404
|
"topicSubModel",
|
|
422
405
|
true
|
|
423
406
|
);
|
|
424
|
-
await sleep(200, true);
|
|
425
407
|
|
|
426
408
|
log(`Get subModelsOutdoor details...`);
|
|
427
409
|
const subModelsOutdoor = await getTopicDetails(
|
|
@@ -430,7 +412,6 @@ const getObject = async (
|
|
|
430
412
|
"topicSubModel",
|
|
431
413
|
true
|
|
432
414
|
);
|
|
433
|
-
await sleep(200, true);
|
|
434
415
|
|
|
435
416
|
log(`Get subModelsDecorative details...`);
|
|
436
417
|
const subModelsDecorative = await getTopicDetails(
|
|
@@ -439,7 +420,6 @@ const getObject = async (
|
|
|
439
420
|
"topicSubModel",
|
|
440
421
|
true
|
|
441
422
|
);
|
|
442
|
-
await sleep(200, true);
|
|
443
423
|
|
|
444
424
|
log(`Get productLine details...`);
|
|
445
425
|
const productLine = await getTopicDetails(
|
|
@@ -448,7 +428,6 @@ const getObject = async (
|
|
|
448
428
|
"topicProductLine",
|
|
449
429
|
true
|
|
450
430
|
);
|
|
451
|
-
await sleep(200, true);
|
|
452
431
|
|
|
453
432
|
log(`Get productSubLine details...`);
|
|
454
433
|
const productSubLine = await getTopicDetails(
|
|
@@ -457,20 +436,17 @@ const getObject = async (
|
|
|
457
436
|
"topicProductSubLine",
|
|
458
437
|
true
|
|
459
438
|
);
|
|
460
|
-
await sleep(200, true);
|
|
461
439
|
|
|
462
440
|
log(`Get autoDescription...`);
|
|
463
441
|
const autoDescription = await getTopicProductAutodescription(
|
|
464
442
|
topicProductWithFields
|
|
465
443
|
);
|
|
466
|
-
await sleep(200, true);
|
|
467
444
|
|
|
468
445
|
log(`Get thumbnail details...`);
|
|
469
446
|
const thumbnail = await getEntryImageDetails(
|
|
470
447
|
topicProductWithFields,
|
|
471
448
|
"thumbnail"
|
|
472
449
|
);
|
|
473
|
-
await sleep(200, true);
|
|
474
450
|
|
|
475
451
|
log(`Get designers details...`);
|
|
476
452
|
const designers = await getTopicDetails(
|
|
@@ -479,7 +455,6 @@ const getObject = async (
|
|
|
479
455
|
"topicDesigner",
|
|
480
456
|
true
|
|
481
457
|
);
|
|
482
|
-
await sleep(200, true);
|
|
483
458
|
|
|
484
459
|
// Single record
|
|
485
460
|
const record: AlgoliaProductRecord = {
|
|
@@ -562,18 +537,17 @@ const getObjects = async (
|
|
|
562
537
|
offset: number,
|
|
563
538
|
limit: number
|
|
564
539
|
): Promise<AlgoliaPaginateRecords> => {
|
|
565
|
-
const
|
|
566
|
-
const env = await getEnvironment();
|
|
540
|
+
const client = await getClient();
|
|
567
541
|
|
|
568
542
|
const opts: any = {
|
|
569
543
|
content_type: "topicProduct",
|
|
570
544
|
limit,
|
|
571
545
|
skip: offset,
|
|
572
|
-
locale:
|
|
546
|
+
locale: "*",
|
|
573
547
|
select: topicProductSelect,
|
|
574
548
|
};
|
|
575
549
|
opts[filterKey] = filterValue;
|
|
576
|
-
const { items, total } = await
|
|
550
|
+
const { items, total } = await client.getEntries(opts);
|
|
577
551
|
|
|
578
552
|
const objects: AlgoliaProductRecord[] = [];
|
|
579
553
|
let count: number = Number(offset);
|
|
@@ -585,10 +559,6 @@ const getObjects = async (
|
|
|
585
559
|
const seconds = secondBetweenTwoDate(timeStart, timeEnd);
|
|
586
560
|
log(`Execution time: ${seconds} seconds`);
|
|
587
561
|
objects.push(record);
|
|
588
|
-
|
|
589
|
-
if (count % 7 === 0) {
|
|
590
|
-
await sleep(2000, true);
|
|
591
|
-
}
|
|
592
562
|
}
|
|
593
563
|
|
|
594
564
|
return {
|
package/src/algolia/subModels.ts
CHANGED
|
@@ -1,25 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
2
|
* SubModel index
|
|
4
|
-
*
|
|
5
|
-
* Esempio singolo record
|
|
6
|
-
* - name
|
|
7
|
-
* - thumbnail
|
|
8
|
-
* - productCounter - numero di prodotti associati a questo topicSubModel
|
|
9
|
-
* - productLine
|
|
10
|
-
* - parentModel
|
|
11
|
-
* - catalog
|
|
12
|
-
* - priority
|
|
13
3
|
*/
|
|
14
4
|
import {
|
|
15
|
-
|
|
16
|
-
// getAllEntries,
|
|
17
|
-
getEntryByID,
|
|
5
|
+
getClient,
|
|
18
6
|
getEnvironmentDefaultLocaleCode,
|
|
19
|
-
|
|
20
|
-
|
|
7
|
+
getEntryByID,
|
|
8
|
+
getAllEntries,
|
|
21
9
|
getTopicDetails,
|
|
22
|
-
|
|
10
|
+
getEntryImageDetails,
|
|
11
|
+
} from "../libs/contenful-cda";
|
|
23
12
|
import {
|
|
24
13
|
CfLocalizedEntryField,
|
|
25
14
|
TopicDetailsResponse,
|
|
@@ -36,7 +25,6 @@ import {
|
|
|
36
25
|
capitalizeFirstLetter,
|
|
37
26
|
keysToLowerCase,
|
|
38
27
|
addProductFieldValueCodesByPimDetails,
|
|
39
|
-
sleep,
|
|
40
28
|
} from "../utils";
|
|
41
29
|
import productFieldsRequiredData from "../pim/data/productFields.json";
|
|
42
30
|
|
|
@@ -150,7 +138,6 @@ const getObject = async (
|
|
|
150
138
|
log(`The topicSubModel with id ${topicSubModelId} not found`, "WARN");
|
|
151
139
|
return { objectID: topicSubModelId };
|
|
152
140
|
}
|
|
153
|
-
await sleep(200, true);
|
|
154
141
|
|
|
155
142
|
log(`Get catalog details...`);
|
|
156
143
|
const catalogs = await getTopicDetails(
|
|
@@ -160,7 +147,6 @@ const getObject = async (
|
|
|
160
147
|
true
|
|
161
148
|
);
|
|
162
149
|
const catalog = catalogs?.[0];
|
|
163
|
-
await sleep(200, true);
|
|
164
150
|
let productFields = [];
|
|
165
151
|
if (!catalog) {
|
|
166
152
|
log(
|
|
@@ -175,7 +161,6 @@ const getObject = async (
|
|
|
175
161
|
topicSubModelWithFields,
|
|
176
162
|
catalogCode
|
|
177
163
|
);
|
|
178
|
-
await sleep(200, true);
|
|
179
164
|
}
|
|
180
165
|
}
|
|
181
166
|
|
|
@@ -187,7 +172,6 @@ const getObject = async (
|
|
|
187
172
|
true
|
|
188
173
|
);
|
|
189
174
|
const productLine = productLines?.[0];
|
|
190
|
-
await sleep(200, true);
|
|
191
175
|
|
|
192
176
|
log(`Get parentModel details...`);
|
|
193
177
|
const parentModels = await getTopicDetails(
|
|
@@ -197,7 +181,6 @@ const getObject = async (
|
|
|
197
181
|
true
|
|
198
182
|
);
|
|
199
183
|
const parentModel = parentModels?.[0];
|
|
200
|
-
await sleep(200, true);
|
|
201
184
|
|
|
202
185
|
log(`Get subFamily details...`);
|
|
203
186
|
const subFamilies = await getTopicDetails(
|
|
@@ -207,14 +190,12 @@ const getObject = async (
|
|
|
207
190
|
true
|
|
208
191
|
);
|
|
209
192
|
const subFamily = subFamilies?.[0];
|
|
210
|
-
await sleep(200, true);
|
|
211
193
|
|
|
212
194
|
log(`Get thumbnail details...`);
|
|
213
195
|
const thumbnail = await getEntryImageDetails(
|
|
214
196
|
topicSubModelWithFields,
|
|
215
197
|
"thumbnail"
|
|
216
198
|
);
|
|
217
|
-
await sleep(200, true);
|
|
218
199
|
|
|
219
200
|
const record: AlgoliaSubModelRecord = {
|
|
220
201
|
objectID: topicSubModelWithFields.sys.id,
|
|
@@ -273,20 +254,19 @@ const getObjects = async (
|
|
|
273
254
|
limit: number,
|
|
274
255
|
catalogCode?: AvailableCatalogs
|
|
275
256
|
): Promise<AlgoliaPaginateRecords> => {
|
|
276
|
-
const
|
|
277
|
-
const env = await getEnvironment();
|
|
257
|
+
const client = await getClient();
|
|
278
258
|
|
|
279
259
|
const opts: any = {
|
|
280
260
|
content_type: "topicSubModel",
|
|
281
261
|
limit,
|
|
282
262
|
skip: offset,
|
|
283
|
-
locale:
|
|
263
|
+
locale: "*",
|
|
284
264
|
select: topicSubModelSelect,
|
|
285
265
|
};
|
|
286
266
|
if (catalogCode) {
|
|
287
267
|
opts["fields.catalog.sys.id"] = catalogCode;
|
|
288
268
|
}
|
|
289
|
-
const { items, total } = await
|
|
269
|
+
const { items, total } = await client.getEntries(opts);
|
|
290
270
|
|
|
291
271
|
const objects: AlgoliaSubModelRecord[] = [];
|
|
292
272
|
let count: number = Number(offset);
|