@bytebrand/export-cars 1.23.3 → 1.24.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytebrand/export-cars",
3
- "version": "1.23.3",
3
+ "version": "1.24.0",
4
4
  "description": "",
5
5
  "author": "bytebrand",
6
6
  "license": "UNLICENSED",
@@ -202,7 +202,7 @@ export class ImagesService {
202
202
 
203
203
 
204
204
  if (!ignoreDefImages && imageWithUrls.length < FB_MAX_IMAGE_COUNT_FOR_DEAFULT) {
205
- imageWithUrls.map(i => i.url).push(...this.DEFAULT_IMAGES);
205
+ this.DEFAULT_IMAGES.forEach(url => imageWithUrls.push({ url }));
206
206
  }
207
207
 
208
208
  return imageWithUrls.map(i => i.url);
@@ -116,31 +116,24 @@ export class FbTransformer {
116
116
  interior_color: this.getInteriorColor(car),
117
117
  condition: this.mapCondition(car),
118
118
  energy_efficiency_class_eu: this.getEnergyEfficiencyClass(car),
119
- vehicle_specifications: [
120
- {
121
- type: 'gas_mileage_combined',
122
- units: 'l/100km',
123
- value: get(car, 'consumption.wltpCombined', ''),
124
- },
125
- {
126
- type: 'gas_mileage_city',
127
- units: 'l/100km',
128
- value: get(car, 'consumption.wltpSlow', ''),
129
- },
130
- {
131
- type: 'gas_mileage_highway',
132
- units: 'l/100km',
133
- value: get(car, 'consumption.wltpVeryFast', ''),
134
- },
135
- {
136
- type: 'CO2_emissions',
137
- units: 'g/km',
138
- value: get(car, 'environmentEmissions.wltpCo2', ''),
139
- },
140
- ],
119
+ vehicle_specifications: this.getVehicleSpecifications(car),
141
120
  };
142
121
  }
143
122
 
123
+ // wltp* fields are @IsOptional on the schema — genuinely absent for a meaningful share of
124
+ // cars (older listings, incomplete imports). Omit the whole entry rather than emit a spec
125
+ // with an empty <value>, but keep legitimate 0 (e.g. CO2 for an EV) — isPresent, not truthy.
126
+ private getVehicleSpecifications(car: DataSchemes.Car): { type: string; units: string; value: number }[] {
127
+ const isPresent = (value: unknown): value is number => value !== null && value !== undefined && value !== '';
128
+
129
+ return [
130
+ { type: 'gas_mileage_combined', units: 'l/100km', value: get(car, 'consumption.wltpCombined') },
131
+ { type: 'gas_mileage_city', units: 'l/100km', value: get(car, 'consumption.wltpSlow') },
132
+ { type: 'gas_mileage_highway', units: 'l/100km', value: get(car, 'consumption.wltpVeryFast') },
133
+ { type: 'CO2_emissions', units: 'g/km', value: get(car, 'environmentEmissions.wltpCo2') },
134
+ ].filter(spec => isPresent(spec.value));
135
+ }
136
+
144
137
  private getYear(car: DataSchemes.Car): number {
145
138
  const firstModelsProductionDate = get(car, 'mainData.firstModelsProductionDate', 0) as number;
146
139
  const firstModelsProductionYear = moment(firstModelsProductionDate * 1000).format('YYYY');
@@ -444,7 +437,7 @@ export class FbTransformer {
444
437
  { key: 'assistants.laneAssistant', type: 'lane_keep_assist', value: 'Spurhalte-Assistent' },
445
438
  { key: 'lights.ledHeadlights', type: 'led_headlights', value: 'LED Scheinwerfer' },
446
439
  { key: 'window.sunroof', type: 'moon_roof', value: 'Schiebedach' },
447
- { key: 'multimedia.mp3Interface', type: 'mp3 MP3', value: 'Schnittstelle' },
440
+ { key: 'multimedia.mp3Interface', type: 'mp3', value: 'Schnittstelle' },
448
441
  { key: 'multimedia.navigationSystem', type: 'navigation', value: 'Navigationssystem' },
449
442
  { key: 'assistants.nightVisionAssistant', type: 'night_view', value: 'Nachsicht Assistent' },
450
443
  { key: 'window.panoramicGlassRoof', type: 'panorama_roof', value: 'Panoramaschiebedach' },
@@ -670,6 +663,12 @@ export class FbTransformer {
670
663
  }
671
664
  }
672
665
 
666
+ // Upper-bounded so a raw unix timestamp leaking through a non-date field (e.g.
667
+ // mainData.constructionYear stored as an epoch instead of a 4-digit year, seen in prod) can't
668
+ // be mistaken for a valid year — a timestamp is astronomically larger than any real car year.
673
669
  function getFirstValidYear(...years: string[]): number {
674
- return years.map((year: string) => toSafeInteger(year)).filter((year: number) => year > TIMESTAMP_FIRST_YEAR)[0];
670
+ const currentYear = toSafeInteger(moment().format('YYYY'));
671
+ return years
672
+ .map((year: string) => toSafeInteger(year))
673
+ .filter((year: number) => year > TIMESTAMP_FIRST_YEAR && year <= currentYear + 1)[0];
675
674
  }