@bytebrand/export-cars 1.23.1 → 1.23.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytebrand/export-cars",
3
- "version": "1.23.1",
3
+ "version": "1.23.2",
4
4
  "description": "",
5
5
  "author": "bytebrand",
6
6
  "license": "UNLICENSED",
@@ -118,14 +118,14 @@ export class FacebookShopTransformer {
118
118
  // matching exactly what the CDP displays (per ticket: data.rate.*/data.leasing.*).
119
119
  const offersFinancing = get(car, 'rate.offersFinancing') !== false;
120
120
  const rawFinancing = {
121
- monthlyPayment: get(car, 'rate.monthlyInstallment', 0),
122
- downPayment: get(car, 'rate.firstInstallment', 0),
123
- termLength: get(car, 'rate.paybackPeriod', 0),
121
+ monthlyPayment: this.getNum(car, 'rate.monthlyInstallment'),
122
+ downPayment: this.getNum(car, 'rate.firstInstallment'),
123
+ termLength: this.getNum(car, 'rate.paybackPeriod'),
124
124
  };
125
125
  const rawLeasing = {
126
- monthlyPayment: get(car, 'leasing.monthlyInstallment', 0),
127
- downPayment: get(car, 'leasing.firstInstallment', 0),
128
- termLength: get(car, 'leasing.paybackPeriod', 0),
126
+ monthlyPayment: this.getNum(car, 'leasing.monthlyInstallment'),
127
+ downPayment: this.getNum(car, 'leasing.firstInstallment'),
128
+ termLength: this.getNum(car, 'leasing.paybackPeriod'),
129
129
  };
130
130
  const leasingIsEligible = this.isLeasingEligible(car);
131
131
 
@@ -140,10 +140,10 @@ export class FacebookShopTransformer {
140
140
  disclaimer: OFFER_DISCLAIMER,
141
141
  financials: {
142
142
  ...rawFinancing,
143
- apr: get(computedFinancing, 'annualPercentageRate', 0),
144
- finalPayment: get(computedFinancing, 'finalInstallment', 0),
145
- totalAmount: get(computedFinancing, 'grossLoanAmount', 0),
146
- netLoanAmount: get(computedFinancing, 'netLoanAmount', 0),
143
+ apr: this.getNum(computedFinancing, 'annualPercentageRate'),
144
+ finalPayment: this.getNum(computedFinancing, 'finalInstallment'),
145
+ totalAmount: this.getNum(computedFinancing, 'grossLoanAmount'),
146
+ netLoanAmount: this.getNum(computedFinancing, 'netLoanAmount'),
147
147
  },
148
148
  });
149
149
  }
@@ -157,10 +157,10 @@ export class FacebookShopTransformer {
157
157
  disclaimer: OFFER_DISCLAIMER,
158
158
  financials: {
159
159
  ...rawLeasing,
160
- apr: get(computedLeasing, 'annualPercentageRate', 0),
161
- finalPayment: get(computedLeasing, 'finalInstallment', 0),
162
- totalAmount: get(computedLeasing, 'grossLoanAmount', 0),
163
- netLoanAmount: get(computedLeasing, 'netLoanAmount', 0),
160
+ apr: this.getNum(computedLeasing, 'annualPercentageRate'),
161
+ finalPayment: this.getNum(computedLeasing, 'finalInstallment'),
162
+ totalAmount: this.getNum(computedLeasing, 'grossLoanAmount'),
163
+ netLoanAmount: this.getNum(computedLeasing, 'netLoanAmount'),
164
164
  },
165
165
  });
166
166
  }
@@ -194,10 +194,10 @@ export class FacebookShopTransformer {
194
194
  // Mirrors getLeasing.ts's isLeasingActive: same car ages out of leasing eligibility once
195
195
  // it's older than leasing.maxAge months or past leasing.maxMileage km.
196
196
  private isLeasingEligible(car: DataSchemes.Car): boolean {
197
- const firstRegistration = get(car, 'mainData.firstRegistration', 0) as number;
198
- const mileage = get(car, 'mainData.mileage', 0) as number;
199
- const maxAge = get(car, 'leasing.maxAge', 24) as number;
200
- const maxMileage = get(car, 'leasing.maxMileage', 1000000) as number;
197
+ const firstRegistration = this.getNum(car, 'mainData.firstRegistration');
198
+ const mileage = this.getNum(car, 'mainData.mileage');
199
+ const maxAge = this.getNum(car, 'leasing.maxAge', 24);
200
+ const maxMileage = this.getNum(car, 'leasing.maxMileage', 1000000);
201
201
 
202
202
  const registrationMs = firstRegistration ? firstRegistration * 1000 : Date.now();
203
203
  const maxCarAge = new Date().setMonth(new Date().getMonth() - maxAge);
@@ -221,6 +221,13 @@ export class FacebookShopTransformer {
221
221
  return { value, isGoogle };
222
222
  }
223
223
 
224
+ // lodash's get() only falls back to the default for an *undefined* path — an explicit
225
+ // `null` stored on the Car document (a common Mongo pattern for "not set") passes
226
+ // straight through and ends up rendering as an empty XML tag. Coalesce it here instead.
227
+ private getNum(source: any, path: string, fallback = 0): number {
228
+ return get(source, path) ?? fallback;
229
+ }
230
+
224
231
  private formatEUR(value: number): string {
225
232
  return Math.round(value || 0).toLocaleString(DE_LOCALE);
226
233
  }
@@ -233,7 +240,7 @@ export class FacebookShopTransformer {
233
240
  }
234
241
 
235
242
  private getYear(car: DataSchemes.Car): string {
236
- const firstRegistration = get(car, 'mainData.firstRegistration', 0) as number;
243
+ const firstRegistration = this.getNum(car, 'mainData.firstRegistration');
237
244
  return firstRegistration ? moment(firstRegistration * 1000).format('YYYY') : moment().format('YYYY');
238
245
  }
239
246
 
@@ -252,7 +259,7 @@ export class FacebookShopTransformer {
252
259
  }
253
260
 
254
261
  private getPriceValue(car: DataSchemes.Car): number {
255
- return round(get(car, 'price.currentSalesPrice', 0), 2);
262
+ return round(this.getNum(car, 'price.currentSalesPrice'), 2);
256
263
  }
257
264
 
258
265
  private getColor(car: DataSchemes.Car): string {