pim-import 4.3.2 → 4.5.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/downloads.js +2 -2
- package/dist/algolia/downloads.js.map +1 -1
- package/dist/algolia/families.js +2 -2
- package/dist/algolia/families.js.map +1 -1
- package/dist/algolia/models.js +5 -5
- package/dist/algolia/models.js.map +1 -1
- package/dist/algolia/news.js +3 -3
- package/dist/algolia/news.js.map +1 -1
- package/dist/algolia/pressRelease.js +3 -3
- package/dist/algolia/pressRelease.js.map +1 -1
- package/dist/algolia/pressReview.js +1 -1
- package/dist/algolia/pressReview.js.map +1 -1
- package/dist/algolia/products.js +20 -20
- package/dist/algolia/products.js.map +1 -1
- package/dist/algolia/projects.js +1 -1
- package/dist/algolia/projects.js.map +1 -1
- package/dist/algolia/stories.js +8 -10
- package/dist/algolia/stories.js.map +1 -1
- package/dist/algolia/subFamilies.js +5 -5
- package/dist/algolia/subFamilies.js.map +1 -1
- package/dist/algolia/subModels.js +6 -6
- package/dist/algolia/subModels.js.map +1 -1
- package/dist/browser.js +2 -2
- package/dist/browser.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/libs/contentful-cda.js +6 -11
- package/dist/libs/contentful-cda.js.map +1 -1
- package/dist/libs/contentful.js +13 -19
- package/dist/libs/contentful.js.map +1 -1
- package/dist/libs/imgix.js +3 -3
- package/dist/libs/imgix.js.map +1 -1
- package/dist/libs/pdf.js +52 -0
- package/dist/libs/pdf.js.map +1 -0
- package/dist/pim/methods/products.js +13 -15
- package/dist/pim/methods/products.js.map +1 -1
- package/dist/utils.js +11 -1
- package/dist/utils.js.map +1 -1
- package/package.json +1 -2
- package/src/algolia/downloads.ts +1 -3
- package/src/algolia/families.ts +2 -4
- package/src/algolia/models.ts +4 -7
- package/src/algolia/news.ts +10 -4
- package/src/algolia/pressRelease.ts +11 -4
- package/src/algolia/pressReview.ts +8 -2
- package/src/algolia/products.ts +9 -26
- package/src/algolia/projects.ts +6 -2
- package/src/algolia/stories.ts +21 -12
- package/src/algolia/subFamilies.ts +9 -9
- package/src/algolia/subModels.ts +10 -10
- package/src/browser.ts +1 -1
- package/src/index.ts +1 -1
- package/src/libs/contentful-cda.ts +17 -15
- package/src/libs/contentful.ts +15 -24
- package/src/libs/imgix.ts +6 -4
- package/src/libs/pdf.ts +89 -0
- package/src/pim/methods/products.ts +14 -15
- package/src/utils.ts +22 -0
- package/types/browser.d.ts +1 -1
- package/types/index.d.ts +1 -1
- package/types/libs/contentful-cda.d.ts +1 -1
- package/types/libs/contentful.d.ts +1 -1
- package/types/libs/pdf.d.ts +17 -0
- package/types/libs/puppeteer.d.ts +1 -1
- package/types/pim/methods/products.d.ts +1 -1
- package/types/utils.d.ts +1 -0
- package/dist/libs/puppeteer.js +0 -171
- package/dist/libs/puppeteer.js.map +0 -1
- package/src/libs/puppeteer.ts +0 -263
package/src/algolia/products.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { getIndex, AvailableIndicesKey, removeIndexObject } from "./config";
|
|
|
19
19
|
import {
|
|
20
20
|
getLocalISOTime,
|
|
21
21
|
secondBetweenTwoDate,
|
|
22
|
-
|
|
22
|
+
getAllTranslations,
|
|
23
23
|
} from "../utils";
|
|
24
24
|
import { getWrapperImgixFields } from "../libs/imgix";
|
|
25
25
|
import axios from "@atoms-studio/axios";
|
|
@@ -127,7 +127,7 @@ const getObject = async (
|
|
|
127
127
|
"sys,fields.slug,fields.protected"
|
|
128
128
|
);
|
|
129
129
|
|
|
130
|
-
const slugs =
|
|
130
|
+
const slugs = await getAllTranslations(productPage?.fields?.slug || {});
|
|
131
131
|
const isProtected =
|
|
132
132
|
!!productPage?.fields?.protected?.[defaultEnvironmentLocaleCode];
|
|
133
133
|
|
|
@@ -135,40 +135,35 @@ const getObject = async (
|
|
|
135
135
|
const catalogs = await getTopicDetails(
|
|
136
136
|
topicProductWithFields,
|
|
137
137
|
"catalogs",
|
|
138
|
-
"topicCatalog"
|
|
139
|
-
true
|
|
138
|
+
"topicCatalog"
|
|
140
139
|
);
|
|
141
140
|
|
|
142
141
|
log(`Get categoriesArchitectural details...`);
|
|
143
142
|
const categoriesArchitectural = await getTopicDetails(
|
|
144
143
|
topicProductWithFields,
|
|
145
144
|
"categoriesArchitectural",
|
|
146
|
-
"topicCategory"
|
|
147
|
-
true
|
|
145
|
+
"topicCategory"
|
|
148
146
|
);
|
|
149
147
|
|
|
150
148
|
log(`Get categoriesOutdoor details...`);
|
|
151
149
|
const categoriesOutdoor = await getTopicDetails(
|
|
152
150
|
topicProductWithFields,
|
|
153
151
|
"categoriesOutdoor",
|
|
154
|
-
"topicCategory"
|
|
155
|
-
true
|
|
152
|
+
"topicCategory"
|
|
156
153
|
);
|
|
157
154
|
|
|
158
155
|
log(`Get categoriesDecorative details...`);
|
|
159
156
|
const categoriesDecorative = await getTopicDetails(
|
|
160
157
|
topicProductWithFields,
|
|
161
158
|
"categoriesDecorative",
|
|
162
|
-
"topicCategory"
|
|
163
|
-
true
|
|
159
|
+
"topicCategory"
|
|
164
160
|
);
|
|
165
161
|
|
|
166
162
|
log(`Get families details...`);
|
|
167
163
|
const families = await getTopicDetails(
|
|
168
164
|
topicProductWithFields,
|
|
169
165
|
"families",
|
|
170
|
-
"topicFamily"
|
|
171
|
-
true
|
|
166
|
+
"topicFamily"
|
|
172
167
|
);
|
|
173
168
|
|
|
174
169
|
log(`Get subFamiliesArchitectural details...`);
|
|
@@ -176,7 +171,6 @@ const getObject = async (
|
|
|
176
171
|
topicProductWithFields,
|
|
177
172
|
"subFamiliesArchitectural",
|
|
178
173
|
"topicSubFamily",
|
|
179
|
-
true,
|
|
180
174
|
false,
|
|
181
175
|
true,
|
|
182
176
|
true
|
|
@@ -187,7 +181,6 @@ const getObject = async (
|
|
|
187
181
|
topicProductWithFields,
|
|
188
182
|
"subFamiliesOutdoor",
|
|
189
183
|
"topicSubFamily",
|
|
190
|
-
true,
|
|
191
184
|
false,
|
|
192
185
|
true,
|
|
193
186
|
true
|
|
@@ -198,7 +191,6 @@ const getObject = async (
|
|
|
198
191
|
topicProductWithFields,
|
|
199
192
|
"subFamiliesDecorative",
|
|
200
193
|
"topicSubFamily",
|
|
201
|
-
true,
|
|
202
194
|
false,
|
|
203
195
|
true,
|
|
204
196
|
true
|
|
@@ -209,7 +201,6 @@ const getObject = async (
|
|
|
209
201
|
topicProductWithFields,
|
|
210
202
|
"modelsArchitectural",
|
|
211
203
|
"topicModel",
|
|
212
|
-
true,
|
|
213
204
|
false,
|
|
214
205
|
true,
|
|
215
206
|
true
|
|
@@ -220,7 +211,6 @@ const getObject = async (
|
|
|
220
211
|
topicProductWithFields,
|
|
221
212
|
"modelsOutdoor",
|
|
222
213
|
"topicModel",
|
|
223
|
-
true,
|
|
224
214
|
false,
|
|
225
215
|
true,
|
|
226
216
|
true
|
|
@@ -231,7 +221,6 @@ const getObject = async (
|
|
|
231
221
|
topicProductWithFields,
|
|
232
222
|
"modelsDecorative",
|
|
233
223
|
"topicModel",
|
|
234
|
-
true,
|
|
235
224
|
false,
|
|
236
225
|
true,
|
|
237
226
|
true
|
|
@@ -242,7 +231,6 @@ const getObject = async (
|
|
|
242
231
|
topicProductWithFields,
|
|
243
232
|
"subModelsArchitectural",
|
|
244
233
|
"topicSubModel",
|
|
245
|
-
true,
|
|
246
234
|
false,
|
|
247
235
|
true,
|
|
248
236
|
true
|
|
@@ -253,7 +241,6 @@ const getObject = async (
|
|
|
253
241
|
topicProductWithFields,
|
|
254
242
|
"subModelsOutdoor",
|
|
255
243
|
"topicSubModel",
|
|
256
|
-
true,
|
|
257
244
|
false,
|
|
258
245
|
true,
|
|
259
246
|
true
|
|
@@ -264,7 +251,6 @@ const getObject = async (
|
|
|
264
251
|
topicProductWithFields,
|
|
265
252
|
"subModelsDecorative",
|
|
266
253
|
"topicSubModel",
|
|
267
|
-
true,
|
|
268
254
|
false,
|
|
269
255
|
true,
|
|
270
256
|
true
|
|
@@ -275,7 +261,6 @@ const getObject = async (
|
|
|
275
261
|
topicProductWithFields,
|
|
276
262
|
"productLine",
|
|
277
263
|
"topicProductLine",
|
|
278
|
-
true,
|
|
279
264
|
false,
|
|
280
265
|
true,
|
|
281
266
|
true
|
|
@@ -286,7 +271,6 @@ const getObject = async (
|
|
|
286
271
|
topicProductWithFields,
|
|
287
272
|
"productSubLine",
|
|
288
273
|
"topicProductSubLine",
|
|
289
|
-
true,
|
|
290
274
|
false,
|
|
291
275
|
true,
|
|
292
276
|
true
|
|
@@ -336,7 +320,6 @@ const getObject = async (
|
|
|
336
320
|
topicProductWithFields,
|
|
337
321
|
"designers",
|
|
338
322
|
"topicDesigner",
|
|
339
|
-
true,
|
|
340
323
|
false,
|
|
341
324
|
true,
|
|
342
325
|
true
|
|
@@ -350,7 +333,7 @@ const getObject = async (
|
|
|
350
333
|
name:
|
|
351
334
|
topicProductWithFields?.fields?.name?.[defaultEnvironmentLocaleCode] ||
|
|
352
335
|
"",
|
|
353
|
-
names: topicProductWithFields?.fields?.name || {},
|
|
336
|
+
names: await getAllTranslations(topicProductWithFields?.fields?.name || {}),
|
|
354
337
|
code:
|
|
355
338
|
topicProductWithFields?.fields?.code?.[defaultEnvironmentLocaleCode] ||
|
|
356
339
|
"",
|
|
@@ -358,7 +341,7 @@ const getObject = async (
|
|
|
358
341
|
isProtected,
|
|
359
342
|
// description: topicProductWithFields?.fields?.description, // Rimosso perché in caluni prodotti si superava il limite massimo della dimensione del record (10000 bytes). es: F0070054
|
|
360
343
|
// excerpt: topicProductWithFields?.fields?.excerpt, // Rimosso perché in caluni prodotti si superava il limite massimo della dimensione del record (10000 bytes). es: F0070054
|
|
361
|
-
autoDescription:
|
|
344
|
+
autoDescription: await getAllTranslations(autoDescription || {}),
|
|
362
345
|
thumbnailImgix,
|
|
363
346
|
catalogs,
|
|
364
347
|
categoriesArchitectural,
|
package/src/algolia/projects.ts
CHANGED
|
@@ -6,7 +6,11 @@ import {
|
|
|
6
6
|
getTopicPage,
|
|
7
7
|
} from "../libs/contentful-cda";
|
|
8
8
|
import { getIndex, AvailableIndicesKey, removeIndexObject } from "./config";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
getAllTranslations,
|
|
11
|
+
getLocalISOTime,
|
|
12
|
+
secondBetweenTwoDate,
|
|
13
|
+
} from "../utils";
|
|
10
14
|
import type { Entry } from "contentful-management/dist/typings/entities/entry";
|
|
11
15
|
import {
|
|
12
16
|
CfLocalizedEntryField,
|
|
@@ -82,7 +86,7 @@ const getObject = async (
|
|
|
82
86
|
return recordFail; // return objectID to delete the record if it exists
|
|
83
87
|
}
|
|
84
88
|
|
|
85
|
-
const slugs = page?.fields.slug || {};
|
|
89
|
+
const slugs = await getAllTranslations(page?.fields.slug || {});
|
|
86
90
|
const isProtected = !!page?.fields?.protected?.[defaultEnvironmentLocaleCode];
|
|
87
91
|
|
|
88
92
|
log(`Get thumbnail imgix details...`);
|
package/src/algolia/stories.ts
CHANGED
|
@@ -6,7 +6,11 @@ import {
|
|
|
6
6
|
getTopicPage,
|
|
7
7
|
} from "../libs/contentful-cda";
|
|
8
8
|
import { getIndex, AvailableIndicesKey, removeIndexObject } from "./config";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
getAllTranslations,
|
|
11
|
+
getLocalISOTime,
|
|
12
|
+
secondBetweenTwoDate,
|
|
13
|
+
} from "../utils";
|
|
10
14
|
import type { Entry } from "contentful-management/dist/typings/entities/entry";
|
|
11
15
|
import {
|
|
12
16
|
CfLocalizedEntryField,
|
|
@@ -82,7 +86,7 @@ const getObject = async (topicStory: Entry): Promise<AlgoliaStoryRecord> => {
|
|
|
82
86
|
return recordFail; // return objectID to delete the record if it exists
|
|
83
87
|
}
|
|
84
88
|
|
|
85
|
-
const slugs = page?.fields.slug || {};
|
|
89
|
+
const slugs = await getAllTranslations(page?.fields.slug || {});
|
|
86
90
|
const isProtected = !!page?.fields?.protected?.[defaultEnvironmentLocaleCode];
|
|
87
91
|
|
|
88
92
|
log(`Get Full Screen Image Imgix details...`);
|
|
@@ -152,8 +156,10 @@ const getObject = async (topicStory: Entry): Promise<AlgoliaStoryRecord> => {
|
|
|
152
156
|
if (categoryEntry) {
|
|
153
157
|
category = {
|
|
154
158
|
sysId: topicStory.fields.category[defaultEnvironmentLocaleCode].sys.id,
|
|
155
|
-
title: categoryEntry?.fields?.title,
|
|
156
|
-
priority:
|
|
159
|
+
title: await getAllTranslations(categoryEntry?.fields?.title || {}),
|
|
160
|
+
priority: await getAllTranslations(
|
|
161
|
+
categoryEntry?.fields?.priority || {}
|
|
162
|
+
),
|
|
157
163
|
};
|
|
158
164
|
} else {
|
|
159
165
|
log(`No categoryEntry found`, "WARN");
|
|
@@ -162,10 +168,10 @@ const getObject = async (topicStory: Entry): Promise<AlgoliaStoryRecord> => {
|
|
|
162
168
|
log(`No category found`, "WARN");
|
|
163
169
|
}
|
|
164
170
|
|
|
165
|
-
const
|
|
171
|
+
const clearExcerpt = {};
|
|
166
172
|
for (const locale in topicStoryWithFields?.fields?.excerpt) {
|
|
167
173
|
if (topicStoryWithFields?.fields?.excerpt?.[locale]) {
|
|
168
|
-
(
|
|
174
|
+
(clearExcerpt as any)[locale] = removeMd(
|
|
169
175
|
topicStoryWithFields?.fields?.excerpt?.[locale]
|
|
170
176
|
);
|
|
171
177
|
}
|
|
@@ -174,12 +180,15 @@ const getObject = async (topicStory: Entry): Promise<AlgoliaStoryRecord> => {
|
|
|
174
180
|
// Single record
|
|
175
181
|
const record: AlgoliaStoryRecord = {
|
|
176
182
|
objectID: topicStoryWithFields.sys.id,
|
|
177
|
-
name:
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
+
name: await getAllTranslations(
|
|
184
|
+
topicStoryWithFields?.fields?.title || emptyLocalizedField
|
|
185
|
+
),
|
|
186
|
+
excerpt: await getAllTranslations(
|
|
187
|
+
topicStoryWithFields?.fields?.excerpt ? clearExcerpt : emptyLocalizedField
|
|
188
|
+
),
|
|
189
|
+
description: await getAllTranslations(
|
|
190
|
+
topicStoryWithFields?.fields?.description || emptyLocalizedField
|
|
191
|
+
),
|
|
183
192
|
slugs,
|
|
184
193
|
isProtected,
|
|
185
194
|
fullScreenImageImgix,
|
|
@@ -16,9 +16,9 @@ import {
|
|
|
16
16
|
getLocalISOTime,
|
|
17
17
|
sanitizeValue,
|
|
18
18
|
secondBetweenTwoDate,
|
|
19
|
-
keysToLowerCase,
|
|
20
19
|
addProductFieldValueCodesByPimDetails,
|
|
21
20
|
capitalizeFirstLetter,
|
|
21
|
+
getAllTranslations,
|
|
22
22
|
} from "../utils";
|
|
23
23
|
import { getWrapperImgixFields } from "../libs/imgix";
|
|
24
24
|
import { AlgoliaFamilyRecord, pageResponse } from "./families";
|
|
@@ -258,8 +258,7 @@ const getObject = async (
|
|
|
258
258
|
const catalogs = await getTopicDetails(
|
|
259
259
|
topicSubFamilyWithFields,
|
|
260
260
|
"catalog",
|
|
261
|
-
"topicCatalog"
|
|
262
|
-
true
|
|
261
|
+
"topicCatalog"
|
|
263
262
|
);
|
|
264
263
|
log(`${catalogs?.length} catalogs founded`);
|
|
265
264
|
|
|
@@ -267,8 +266,7 @@ const getObject = async (
|
|
|
267
266
|
const categories = await getTopicDetails(
|
|
268
267
|
topicSubFamilyWithFields,
|
|
269
268
|
"category",
|
|
270
|
-
"topicCategory"
|
|
271
|
-
true
|
|
269
|
+
"topicCategory"
|
|
272
270
|
);
|
|
273
271
|
log(`${categories?.length} categories founded`);
|
|
274
272
|
|
|
@@ -314,15 +312,17 @@ const getObject = async (
|
|
|
314
312
|
// Single record
|
|
315
313
|
const record: AlgoliaFamilyRecord = {
|
|
316
314
|
objectID: topicSubFamilyWithFields.sys.id,
|
|
317
|
-
names:
|
|
315
|
+
names: await getAllTranslations(
|
|
316
|
+
topicSubFamilyWithFields?.fields?.name || {}
|
|
317
|
+
),
|
|
318
318
|
code:
|
|
319
319
|
topicSubFamilyWithFields?.fields?.code?.[defaultEnvironmentLocaleCode] ||
|
|
320
|
-
|
|
320
|
+
"",
|
|
321
321
|
thumbnailImgix,
|
|
322
322
|
fullScreenImageImgix,
|
|
323
|
-
slugs:
|
|
323
|
+
slugs: await getAllTranslations(page?.slugs || {}),
|
|
324
324
|
slugType: page?.type || "",
|
|
325
|
-
// slugDetails: page?.details || {},
|
|
325
|
+
// slugDetails: await getAllTranslations(page?.details || {}),
|
|
326
326
|
catalogs,
|
|
327
327
|
categories,
|
|
328
328
|
productFields,
|
package/src/algolia/subModels.ts
CHANGED
|
@@ -23,8 +23,8 @@ import {
|
|
|
23
23
|
getLocalISOTime,
|
|
24
24
|
secondBetweenTwoDate,
|
|
25
25
|
capitalizeFirstLetter,
|
|
26
|
-
keysToLowerCase,
|
|
27
26
|
addProductFieldValueCodesByPimDetails,
|
|
27
|
+
getAllTranslations,
|
|
28
28
|
} from "../utils";
|
|
29
29
|
import productFieldsRequiredData from "../pim/data/productFields.json";
|
|
30
30
|
import { getWrapperImgixFields } from "../libs/imgix";
|
|
@@ -154,8 +154,7 @@ const getObject = async (
|
|
|
154
154
|
const catalogs = await getTopicDetails(
|
|
155
155
|
topicSubModelWithFields,
|
|
156
156
|
"catalog",
|
|
157
|
-
"topicCatalog"
|
|
158
|
-
true
|
|
157
|
+
"topicCatalog"
|
|
159
158
|
);
|
|
160
159
|
const catalog = catalogs?.[0];
|
|
161
160
|
let productFields = [];
|
|
@@ -179,8 +178,7 @@ const getObject = async (
|
|
|
179
178
|
const productLines = await getTopicDetails(
|
|
180
179
|
topicSubModelWithFields,
|
|
181
180
|
"productLine",
|
|
182
|
-
"topicProductLine"
|
|
183
|
-
true
|
|
181
|
+
"topicProductLine"
|
|
184
182
|
);
|
|
185
183
|
const productLine = productLines?.[0];
|
|
186
184
|
|
|
@@ -188,8 +186,7 @@ const getObject = async (
|
|
|
188
186
|
const parentModels = await getTopicDetails(
|
|
189
187
|
topicSubModelWithFields,
|
|
190
188
|
"parentModel",
|
|
191
|
-
"topicModel"
|
|
192
|
-
true
|
|
189
|
+
"topicModel"
|
|
193
190
|
);
|
|
194
191
|
const parentModel = parentModels?.[0];
|
|
195
192
|
|
|
@@ -198,7 +195,6 @@ const getObject = async (
|
|
|
198
195
|
topicSubModelWithFields,
|
|
199
196
|
"subFamily",
|
|
200
197
|
"topicSubFamily",
|
|
201
|
-
true,
|
|
202
198
|
false,
|
|
203
199
|
true,
|
|
204
200
|
true
|
|
@@ -219,11 +215,15 @@ const getObject = async (
|
|
|
219
215
|
|
|
220
216
|
const record: AlgoliaSubModelRecord = {
|
|
221
217
|
objectID: topicSubModelWithFields.sys.id,
|
|
222
|
-
names:
|
|
218
|
+
names: await getAllTranslations(
|
|
219
|
+
topicSubModelWithFields?.fields?.name || {}
|
|
220
|
+
),
|
|
223
221
|
code:
|
|
224
222
|
topicSubModelWithFields?.fields?.code?.[defaultEnvironmentLocaleCode] ||
|
|
225
223
|
"",
|
|
226
|
-
description:
|
|
224
|
+
description: await getAllTranslations(
|
|
225
|
+
topicSubModelWithFields?.fields?.description || {}
|
|
226
|
+
),
|
|
227
227
|
thumbnailImgix,
|
|
228
228
|
catalog,
|
|
229
229
|
productLine,
|
package/src/browser.ts
CHANGED
|
@@ -112,4 +112,4 @@ export { getLocalISOTime } from "./utils";
|
|
|
112
112
|
export { getStaticDailyProducts } from "./pim/endpoints";
|
|
113
113
|
export { log, setLogId } from "./libs/logs";
|
|
114
114
|
export { removeRecordsByStatus } from "./algolia/clean";
|
|
115
|
-
export { generatePDFByUrl } from "./libs/
|
|
115
|
+
export { generatePDFByUrl } from "./libs/pdf";
|
package/src/index.ts
CHANGED
|
@@ -6,7 +6,11 @@ import {
|
|
|
6
6
|
AssetPropFieldsWithoutLocaleKey,
|
|
7
7
|
OtherFilters,
|
|
8
8
|
} from "../types";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
getPimTranslations,
|
|
11
|
+
keysToLowerCase,
|
|
12
|
+
getAllTranslations,
|
|
13
|
+
} from "../utils";
|
|
10
14
|
import { log } from "./logs";
|
|
11
15
|
const contentful = require("contentful");
|
|
12
16
|
|
|
@@ -255,16 +259,15 @@ export const getEntryImageDetails = async (entry: Entry, fieldKey: string) => {
|
|
|
255
259
|
* @param topicEntry
|
|
256
260
|
* @param fieldKey
|
|
257
261
|
* @param contentType
|
|
258
|
-
* @param lowerCaseKeys Default false
|
|
259
262
|
* @param showRelatedEntities Default false
|
|
260
263
|
* @param isCatalogEntry Default true
|
|
264
|
+
* @param skipPageSlugs Default false
|
|
261
265
|
* @returns
|
|
262
266
|
*/
|
|
263
267
|
export const getTopicDetails = async (
|
|
264
268
|
topicEntry: Entry,
|
|
265
269
|
fieldKey: string,
|
|
266
270
|
contentType: string,
|
|
267
|
-
lowerCaseKeys: boolean = false,
|
|
268
271
|
showRelatedEntities: boolean = false,
|
|
269
272
|
isCatalogEntry: boolean = true,
|
|
270
273
|
skipPageSlugs: boolean = false
|
|
@@ -302,10 +305,7 @@ export const getTopicDetails = async (
|
|
|
302
305
|
if (entries) {
|
|
303
306
|
for (const entry of entries) {
|
|
304
307
|
const data: TopicDetailsResponse = {
|
|
305
|
-
names:
|
|
306
|
-
entry?.fields?.name && lowerCaseKeys
|
|
307
|
-
? keysToLowerCase(entry.fields.name)
|
|
308
|
-
: {},
|
|
308
|
+
names: await getAllTranslations(entry?.fields?.name || {}),
|
|
309
309
|
code: entry?.fields?.code?.[defEnvLocaleCode],
|
|
310
310
|
};
|
|
311
311
|
if (!skipPageSlugs) {
|
|
@@ -316,10 +316,7 @@ export const getTopicDetails = async (
|
|
|
316
316
|
} else {
|
|
317
317
|
entryPage = await getTopicPage(entry.sys.id);
|
|
318
318
|
}
|
|
319
|
-
data.slugs =
|
|
320
|
-
entryPage?.fields?.slug && lowerCaseKeys
|
|
321
|
-
? keysToLowerCase(entryPage.fields.slug)
|
|
322
|
-
: {};
|
|
319
|
+
data.slugs = await getAllTranslations(entryPage?.fields?.slug || {});
|
|
323
320
|
}
|
|
324
321
|
|
|
325
322
|
if (contentType === "topicSubFamily" && showRelatedEntities) {
|
|
@@ -377,10 +374,15 @@ export const getSubFamilySlugDetails = async (topicSubFamily: Entry) => {
|
|
|
377
374
|
: {};
|
|
378
375
|
|
|
379
376
|
return {
|
|
380
|
-
catalogPageSlugs:
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
377
|
+
catalogPageSlugs: await getAllTranslations(
|
|
378
|
+
subFamilyCatalogPage?.fields?.slug || {}
|
|
379
|
+
),
|
|
380
|
+
familyPageSlugs: await getAllTranslations(
|
|
381
|
+
subFamilyFamilyPage?.fields?.slug || {}
|
|
382
|
+
),
|
|
383
|
+
categoryPageSlugs: await getAllTranslations(
|
|
384
|
+
subFamilyCategoryPage?.fields?.slug || {}
|
|
385
|
+
),
|
|
384
386
|
};
|
|
385
387
|
};
|
|
386
388
|
|
package/src/libs/contentful.ts
CHANGED
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
getPimTranslations,
|
|
32
32
|
keysToLowerCase,
|
|
33
33
|
replaceAll,
|
|
34
|
+
getAllTranslations,
|
|
34
35
|
} from "../utils";
|
|
35
36
|
import { getSubFamilySlugDetails } from "../pim/methods/subfamilies";
|
|
36
37
|
import { removeProductObject } from "../algolia/products";
|
|
@@ -1094,18 +1095,18 @@ export const addFieldValue = async (
|
|
|
1094
1095
|
* @param topicEntry
|
|
1095
1096
|
* @param fieldKey
|
|
1096
1097
|
* @param contentType
|
|
1097
|
-
* @param lowerCaseKeys Default false
|
|
1098
1098
|
* @param showRelatedEntities Default false
|
|
1099
1099
|
* @param isCatalogEntry Default true
|
|
1100
|
+
* @param skipPageSlugs Default false
|
|
1100
1101
|
* @returns
|
|
1101
1102
|
*/
|
|
1102
1103
|
export const getTopicDetails = async (
|
|
1103
1104
|
topicEntry: Entry,
|
|
1104
1105
|
fieldKey: string,
|
|
1105
1106
|
contentType: string,
|
|
1106
|
-
lowerCaseKeys: boolean = false,
|
|
1107
1107
|
showRelatedEntities: boolean = false,
|
|
1108
|
-
isCatalogEntry: boolean = true
|
|
1108
|
+
isCatalogEntry: boolean = true,
|
|
1109
|
+
skipPageSlugs: boolean = false
|
|
1109
1110
|
): Promise<TopicDetailsResponse[]> => {
|
|
1110
1111
|
const defEnvLocaleCode = await getEnvironmentDefaultLocaleCode();
|
|
1111
1112
|
const isHasToManyField = Array.isArray(
|
|
@@ -1138,36 +1139,26 @@ export const getTopicDetails = async (
|
|
|
1138
1139
|
);
|
|
1139
1140
|
|
|
1140
1141
|
if (entries) {
|
|
1141
|
-
let count = 0;
|
|
1142
1142
|
for (const entry of entries) {
|
|
1143
|
-
let entryPage: any = {};
|
|
1144
|
-
if (isCatalogEntry) {
|
|
1145
|
-
const entryPageId = `${entry.sys.id}_PAGE`;
|
|
1146
|
-
entryPage = await getEntryByID(entryPageId, "page", "fields.slug");
|
|
1147
|
-
} else {
|
|
1148
|
-
entryPage = await getTopicPage(entry.sys.id);
|
|
1149
|
-
}
|
|
1150
|
-
|
|
1151
1143
|
const data: TopicDetailsResponse = {
|
|
1152
|
-
names:
|
|
1153
|
-
entry?.fields?.name && lowerCaseKeys
|
|
1154
|
-
? keysToLowerCase(entry.fields.name)
|
|
1155
|
-
: {},
|
|
1144
|
+
names: await getAllTranslations(entry?.fields?.name || {}),
|
|
1156
1145
|
code: entry?.fields?.code?.[defEnvLocaleCode],
|
|
1157
|
-
slugs:
|
|
1158
|
-
entryPage?.fields?.slug && lowerCaseKeys
|
|
1159
|
-
? keysToLowerCase(entryPage.fields.slug)
|
|
1160
|
-
: {},
|
|
1161
1146
|
};
|
|
1147
|
+
if (!skipPageSlugs) {
|
|
1148
|
+
let entryPage: any = {};
|
|
1149
|
+
if (isCatalogEntry) {
|
|
1150
|
+
const entryPageId = `${entry.sys.id}_PAGE`;
|
|
1151
|
+
entryPage = await getEntryByID(entryPageId, "page", "fields.slug");
|
|
1152
|
+
} else {
|
|
1153
|
+
entryPage = await getTopicPage(entry.sys.id);
|
|
1154
|
+
}
|
|
1155
|
+
data.slugs = await getAllTranslations(entryPage?.fields?.slug || {});
|
|
1156
|
+
}
|
|
1162
1157
|
|
|
1163
1158
|
if (contentType === "topicSubFamily" && showRelatedEntities) {
|
|
1164
1159
|
data.details = await getSubFamilySlugDetails(entry);
|
|
1165
1160
|
}
|
|
1166
1161
|
|
|
1167
|
-
if (++count > 0 && count % 7 === 0) {
|
|
1168
|
-
await sleep(2000, true);
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
1162
|
items.push(data);
|
|
1172
1163
|
}
|
|
1173
1164
|
}
|
package/src/libs/imgix.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import axios from "@atoms-studio/axios";
|
|
10
10
|
import https from "https";
|
|
11
11
|
import mime from "mime-types";
|
|
12
|
-
import { basename } from "../utils";
|
|
12
|
+
import { basename, getAllTranslations } from "../utils";
|
|
13
13
|
|
|
14
14
|
let imgix: ImgixAPI;
|
|
15
15
|
export const getImgix = () => {
|
|
@@ -204,9 +204,11 @@ export const getWrapperImgixFields = async (wrapperImgixId: string) => {
|
|
|
204
204
|
focalPoint:
|
|
205
205
|
wrapperImgix?.fields?.focalPoint?.[defaultEnvironmentLocaleCode]
|
|
206
206
|
?.focalPoint || {},
|
|
207
|
-
altText: wrapperImgix?.fields?.altText || {},
|
|
208
|
-
caption: wrapperImgix?.fields?.caption || {},
|
|
209
|
-
hoverTitle:
|
|
207
|
+
altText: await getAllTranslations(wrapperImgix?.fields?.altText || {}),
|
|
208
|
+
caption: await getAllTranslations(wrapperImgix?.fields?.caption || {}),
|
|
209
|
+
hoverTitle: await getAllTranslations(
|
|
210
|
+
wrapperImgix?.fields?.hoverTitle || {}
|
|
211
|
+
),
|
|
210
212
|
forceHoverTitle:
|
|
211
213
|
!!wrapperImgix?.fields?.forceHoverTitle?.[defaultEnvironmentLocaleCode],
|
|
212
214
|
};
|
package/src/libs/pdf.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { secondBetweenTwoDate } from "../utils";
|
|
2
|
+
import { log, serverUtils } from "./logs";
|
|
3
|
+
import axios from "@atoms-studio/axios";
|
|
4
|
+
|
|
5
|
+
interface HeaderColumns {
|
|
6
|
+
left?: string;
|
|
7
|
+
right?: string;
|
|
8
|
+
}
|
|
9
|
+
interface FooterColumns {
|
|
10
|
+
topLeft?: string;
|
|
11
|
+
topRight?: string;
|
|
12
|
+
bottomLeft?: string;
|
|
13
|
+
bottomRight?: string;
|
|
14
|
+
mail?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface PDFHeaderAndFooter {
|
|
18
|
+
header?: HeaderColumns;
|
|
19
|
+
footer?: FooterColumns;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const generatePDFByUrl = async (
|
|
23
|
+
url: string,
|
|
24
|
+
fileName: string = "",
|
|
25
|
+
contents?: PDFHeaderAndFooter
|
|
26
|
+
) => {
|
|
27
|
+
const pdf = await generatePDFByAWSLambda(url, fileName, contents);
|
|
28
|
+
|
|
29
|
+
return pdf;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Generate PDF by URL
|
|
34
|
+
*
|
|
35
|
+
* @param url E.g. https://my-site.com/slug
|
|
36
|
+
* @param fileName E.g. my-file.pdf
|
|
37
|
+
* @param contents E.g. {header{left:'Foo', right:'Bar'}, footer{left:'Foo', right:'Bar'}}
|
|
38
|
+
* @returns
|
|
39
|
+
*/
|
|
40
|
+
const generatePDFByAWSLambda = async (
|
|
41
|
+
url: string,
|
|
42
|
+
fileName: string = "",
|
|
43
|
+
contents?: PDFHeaderAndFooter
|
|
44
|
+
) => {
|
|
45
|
+
let logMsg = `generatePDFByUrl - url: ${url}`;
|
|
46
|
+
log(logMsg, "DEBUG");
|
|
47
|
+
if (serverUtils) {
|
|
48
|
+
serverUtils.log(logMsg);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (!process.env.FPID_AWS_GEN_PDF_LAMBDA_URL) {
|
|
52
|
+
logMsg = `FPID_AWS_GEN_PDF_LAMBDA_URL environment variable not found`;
|
|
53
|
+
if (serverUtils) {
|
|
54
|
+
serverUtils.log(logMsg);
|
|
55
|
+
}
|
|
56
|
+
log(logMsg, "ERROR");
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const timeStart = new Date();
|
|
61
|
+
|
|
62
|
+
logMsg = `Axios request...`;
|
|
63
|
+
log(logMsg, "DEBUG");
|
|
64
|
+
if (serverUtils) {
|
|
65
|
+
serverUtils.log(logMsg);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const options: any = {
|
|
69
|
+
method: "POST",
|
|
70
|
+
url: process.env.FPID_AWS_GEN_PDF_LAMBDA_URL,
|
|
71
|
+
data: {
|
|
72
|
+
url,
|
|
73
|
+
fileName,
|
|
74
|
+
contents,
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
const response = await axios.request(options);
|
|
78
|
+
|
|
79
|
+
logMsg = `End axios request - ${secondBetweenTwoDate(
|
|
80
|
+
timeStart,
|
|
81
|
+
new Date()
|
|
82
|
+
)} seconds`;
|
|
83
|
+
log(logMsg, "DEBUG");
|
|
84
|
+
if (serverUtils) {
|
|
85
|
+
serverUtils.log(logMsg);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return response.data;
|
|
89
|
+
};
|