@bytebrand/export-cars 1.24.0 → 1.24.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/exporters/fb.exporter.js +4 -0
- package/dist/exporters/fb.exporter.js.map +1 -1
- package/dist/formats/fb-xml.builder.js +7 -0
- package/dist/formats/fb-xml.builder.js.map +1 -1
- package/dist/transformers/fb.transformer.js +8 -1
- package/dist/transformers/fb.transformer.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/exporters/fb.exporter.ts +5 -0
- package/src/formats/fb-xml.builder.ts +9 -0
- package/src/transformers/fb.transformer.ts +17 -3
package/package.json
CHANGED
|
@@ -41,6 +41,11 @@ export class FbExporter implements Exporter {
|
|
|
41
41
|
const car = await fbTransformer.transform({ owner, ...data });
|
|
42
42
|
console.timeEnd(`Transform ${data.car._id}`);
|
|
43
43
|
|
|
44
|
+
if (!car) {
|
|
45
|
+
console.log(`Skip car ${data.car._id} because it has no real images`);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
44
49
|
await fbXmlBuilder.addItem(car as FbXmlItem);
|
|
45
50
|
this.carService.counter.countCar(data.images);
|
|
46
51
|
}
|
|
@@ -19,6 +19,15 @@ export class FbXmlBuilder extends XMLBuilderBase {
|
|
|
19
19
|
if (key === 'additional_image_link' && Array.isArray(data)) {
|
|
20
20
|
return data.map((value: string) => this.getElement(key, value, true)).join('');
|
|
21
21
|
}
|
|
22
|
+
if (key === 'vehicle_specifications' && Array.isArray(data)) {
|
|
23
|
+
// getElement() treats falsy values as "missing" — stringify so a legitimate 0
|
|
24
|
+
// (e.g. CO2_emissions for an EV) still renders instead of an empty <value>.
|
|
25
|
+
const stringified = data.map((spec: { type: string; units: string; value: number }) => ({
|
|
26
|
+
...spec,
|
|
27
|
+
value: String(spec.value),
|
|
28
|
+
}));
|
|
29
|
+
return this.getElementsArray(key, stringified);
|
|
30
|
+
}
|
|
22
31
|
if (Array.isArray(data)) {
|
|
23
32
|
return this.getElementsArray(key, data);
|
|
24
33
|
}
|
|
@@ -44,6 +44,9 @@ import {
|
|
|
44
44
|
TIMESTAMP_FIRST_YEAR,
|
|
45
45
|
} from '../constants/fb.constants';
|
|
46
46
|
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
48
|
+
const vinGenerator = require('vin-generator');
|
|
49
|
+
|
|
47
50
|
@Injectable()
|
|
48
51
|
export class FbTransformer {
|
|
49
52
|
private translator: TranslatorExtended;
|
|
@@ -71,6 +74,13 @@ export class FbTransformer {
|
|
|
71
74
|
images: ImboImageResponseInterface[];
|
|
72
75
|
owner: unknown;
|
|
73
76
|
}): Promise<unknown> {
|
|
77
|
+
// ignoreDefImages=true: cars with no real photos must be excluded, not padded with
|
|
78
|
+
// placeholders (matches facebook-shop.transformer.ts's AMA feed policy).
|
|
79
|
+
const image_links = await this.imagesService.getImages(car, images, ImageType.marketing, true);
|
|
80
|
+
if (!image_links.length) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
74
84
|
const autodeId = toString(get(car, '_id', ''));
|
|
75
85
|
const year = this.getYear(car);
|
|
76
86
|
const ownerId = get(car, 'metaData.ownerId', null);
|
|
@@ -78,9 +88,6 @@ export class FbTransformer {
|
|
|
78
88
|
// console.time(`Address ${car._id}`);
|
|
79
89
|
const address = await this.getAddress(car, owner);
|
|
80
90
|
// console.timeEnd(`Address ${car._id}`);
|
|
81
|
-
// console.time(`Images ${car._id}`);
|
|
82
|
-
const image_links = await this.imagesService.getImages(car, images, ImageType.marketing, false);
|
|
83
|
-
// console.timeEnd(`Images ${car._id}`);
|
|
84
91
|
|
|
85
92
|
return {
|
|
86
93
|
fb_page_id: '176306386132',
|
|
@@ -218,6 +225,13 @@ export class FbTransformer {
|
|
|
218
225
|
vin = get(car, 'marketing.fakeVIN', '');
|
|
219
226
|
}
|
|
220
227
|
|
|
228
|
+
// Meta requires a vin on every listing. Real + fake VIN are both absent for a small
|
|
229
|
+
// share of cars (marketing.fakeVIN is populated by a different upstream service) —
|
|
230
|
+
// same generated-VIN fallback already used by mobile.transformer.ts/santander.transformer.ts.
|
|
231
|
+
if (!isValidVin(vin)) {
|
|
232
|
+
vin = vinGenerator.generateVin();
|
|
233
|
+
}
|
|
234
|
+
|
|
221
235
|
return vin;
|
|
222
236
|
}
|
|
223
237
|
|