@bytebrand/export-cars 1.26.7 → 1.26.9
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/transformers/fb-description.transformer.js +0 -13
- package/dist/transformers/fb-description.transformer.js.map +1 -1
- package/dist/transformers/fb.transformer.js +3 -6
- package/dist/transformers/fb.transformer.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utils/converter.utils.d.ts +1 -0
- package/dist/utils/converter.utils.js +11 -1
- package/dist/utils/converter.utils.js.map +1 -1
- package/package.json +1 -1
- package/src/transformers/fb-description.transformer.ts +4 -13
- package/src/transformers/fb.transformer.ts +12 -9
- package/src/utils/converter.utils.ts +19 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseCsvToObjects = exports.xmlStringReplacer = exports.convertToCSV = void 0;
|
|
3
|
+
exports.parseCsvToObjects = exports.normalizeFeedText = exports.xmlStringReplacer = exports.convertToCSV = void 0;
|
|
4
4
|
const lodash_1 = require("lodash");
|
|
5
5
|
function convertToCSV(data) {
|
|
6
6
|
const converted = [];
|
|
@@ -16,6 +16,16 @@ const xmlStringReplacer = (str) => {
|
|
|
16
16
|
return typeof str === 'string' ? str.replace(/&/g, '&').replace(/[<>]/g, '') : '';
|
|
17
17
|
};
|
|
18
18
|
exports.xmlStringReplacer = xmlStringReplacer;
|
|
19
|
+
const DISALLOWED_TEXT_CHARS = /[^\p{L}\p{N} .,\-/()%"°]/gu;
|
|
20
|
+
const EDGE_SEPARATORS = /^[\s.,\-/]+|[\s.,\-/]+$/g;
|
|
21
|
+
function normalizeFeedText(text) {
|
|
22
|
+
return (text || '')
|
|
23
|
+
.replace(DISALLOWED_TEXT_CHARS, ' ')
|
|
24
|
+
.replace(/([.,\-/])\1+/g, '$1')
|
|
25
|
+
.replace(/\s+/g, ' ')
|
|
26
|
+
.replace(EDGE_SEPARATORS, '');
|
|
27
|
+
}
|
|
28
|
+
exports.normalizeFeedText = normalizeFeedText;
|
|
19
29
|
function parseCsvToObjects(csv) {
|
|
20
30
|
const rows = [];
|
|
21
31
|
let row = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"converter.utils.js","sourceRoot":"","sources":["../../src/utils/converter.utils.ts"],"names":[],"mappings":";;;AAAA,mCAA6B;AAE7B,SAAgB,YAAY,CAAC,IAAa;IACxC,MAAM,SAAS,GAAG,EAAE,CAAC;IACrB,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE;QAC/B,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAa,CAAC;QAC7B,MAAM,QAAQ,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;QAChE,IAAA,YAAG,EAAC,SAAS,EAAE,CAAC,EAAE,IAAI,QAAQ,GAAG,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;IACH,OAAO,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC;AARD,oCAQC;AAEM,MAAM,iBAAiB,GAAG,CAAC,GAAW,EAAU,EAAE;IACvD,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACxF,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B;
|
|
1
|
+
{"version":3,"file":"converter.utils.js","sourceRoot":"","sources":["../../src/utils/converter.utils.ts"],"names":[],"mappings":";;;AAAA,mCAA6B;AAE7B,SAAgB,YAAY,CAAC,IAAa;IACxC,MAAM,SAAS,GAAG,EA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AAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;IACnF,IAAI,CAAC,MAAM,EAAE;QACX,OAAO,EAAE,CAAC;KACX;IAED,OAAO,QAAQ,CAAC,GAAG,CACjB,OAAO,CAAC,EAAE,CACR,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE;QAC9B,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAC9C,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAA4B,CAAM,CACxC,CAAC;AACJ,CAAC;AAhDD,8CAgDC"}
|
package/package.json
CHANGED
|
@@ -46,13 +46,8 @@ export class FbDescription {
|
|
|
46
46
|
key: get(this.car, 'engineData.cylinders', '') as string,
|
|
47
47
|
},
|
|
48
48
|
},
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
value: {
|
|
52
|
-
key: 'title.cubicCapacity',
|
|
53
|
-
data: { cubicCapacity: get(this.car, 'engineData.cubicCapacity') },
|
|
54
|
-
},
|
|
55
|
-
},
|
|
49
|
+
// "Hubraum" is not exported: the value key resolved to the label itself
|
|
50
|
+
// (title.cubicCapacity === "Hubraum"), so every listing read "Hubraum: Hubraum".
|
|
56
51
|
{
|
|
57
52
|
title: 'accordion.captionPower',
|
|
58
53
|
value: {
|
|
@@ -166,12 +161,8 @@ export class FbDescription {
|
|
|
166
161
|
},
|
|
167
162
|
},
|
|
168
163
|
},
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
value: {
|
|
172
|
-
key: get(this.car, 'driveSuspension.wheelBase', '') as string,
|
|
173
|
-
},
|
|
174
|
-
},
|
|
164
|
+
// "Radstand" is not exported: driveSuspension.wheelBase is stored as null across the
|
|
165
|
+
// catalogue, so every listing read "Radstand: ;".
|
|
175
166
|
{
|
|
176
167
|
title: 'title.loadingVolume',
|
|
177
168
|
value: {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Cache } from 'cache-manager';
|
|
2
2
|
import * as moment from 'moment';
|
|
3
3
|
import {
|
|
4
|
-
escape,
|
|
5
4
|
findIndex,
|
|
6
5
|
get,
|
|
7
6
|
includes,
|
|
@@ -12,7 +11,6 @@ import {
|
|
|
12
11
|
join,
|
|
13
12
|
toSafeInteger,
|
|
14
13
|
toString,
|
|
15
|
-
trim,
|
|
16
14
|
truncate,
|
|
17
15
|
} from 'lodash';
|
|
18
16
|
|
|
@@ -30,7 +28,7 @@ import { Description } from '../interfaces/description.interface';
|
|
|
30
28
|
import { FbDescription } from './fb-description.transformer';
|
|
31
29
|
import { ConfigService, ImagesService, MappingService } from '../services';
|
|
32
30
|
import { FbEquipment } from './fb-equipment.transformer';
|
|
33
|
-
import { isValidVin } from '../utils';
|
|
31
|
+
import { isValidVin, normalizeFeedText } from '../utils';
|
|
34
32
|
import { UserService } from 'src/services';
|
|
35
33
|
import { ImageType } from '../enums';
|
|
36
34
|
import {
|
|
@@ -188,18 +186,23 @@ export class FbTransformer {
|
|
|
188
186
|
}
|
|
189
187
|
|
|
190
188
|
private getTitle(car: DataSchemes.Car): string {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
189
|
+
// mainData.constructionYear holds a raw epoch for part of the catalogue — the same
|
|
190
|
+
// corruption getFirstValidYear() already guards <year> against. Without the guard titles
|
|
191
|
+
// ship as "1609459200 Ford Galaxy …"; an invalid year is dropped instead.
|
|
192
|
+
const year = toString(getFirstValidYear(toString(get(car, 'mainData.constructionYear', ''))));
|
|
195
193
|
const make = toString(get(car, 'mainData.make', ''));
|
|
196
194
|
const model = toString(get(car, 'mainData.model', ''));
|
|
197
195
|
const subModel = toString(get(car, 'mainData.subModel', ''));
|
|
198
|
-
|
|
196
|
+
// No escape() here: FbXmlBuilder writes <title> inside CDATA, so HTML entities are not
|
|
197
|
+
// decoded by the consumer and leak literally ("Monte Carlo & KESSY").
|
|
198
|
+
return normalizeFeedText(join([year, make, model, subModel], ' '));
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
private getTrim(car: DataSchemes.Car): string {
|
|
202
|
-
|
|
202
|
+
// Same subModel source as the title, so it needs the same cleanup. Normalise before
|
|
203
|
+
// truncating: on the raw string the cut could land mid-junk, and lodash's "..." omission
|
|
204
|
+
// marker would then be collapsed by the repeated-separator rule.
|
|
205
|
+
const trim = normalizeFeedText(toString(get(car, 'mainData.subModel', '')));
|
|
203
206
|
return truncate(trim, { length: FB_MAX_TRIM_LENGTH, separator: ' ' });
|
|
204
207
|
}
|
|
205
208
|
|
|
@@ -14,6 +14,25 @@ export const xmlStringReplacer = (str: string): string => {
|
|
|
14
14
|
return typeof str === 'string' ? str.replace(/&/g, '&').replace(/[<>]/g, '') : '';
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
+
// Dealer-supplied subModel strings are full of decorative punctuation ("*AHK*Leder*Navi*",
|
|
18
|
+
// "|ACC|PANO/AHK", "#PANO #NAVI #SONY #", "Head-Up+B&O+ACC") which must not reach Meta. Keep
|
|
19
|
+
// letters, digits and the punctuation that carries meaning in German trim names — "." "," "-"
|
|
20
|
+
// "/" "(" ")" "%", "°" (360° Kamera) and '"' (Zoll). Everything else, "&" included, becomes a
|
|
21
|
+
// space rather than being deleted, so neighbouring words never fuse ("B&O" -> "B O").
|
|
22
|
+
const DISALLOWED_TEXT_CHARS = /[^\p{L}\p{N} .,\-/()%"°]/gu;
|
|
23
|
+
// Leading/trailing separators only; '"' and "%" are legitimate endings (`LM18"`, `-35%`).
|
|
24
|
+
const EDGE_SEPARATORS = /^[\s.,\-/]+|[\s.,\-/]+$/g;
|
|
25
|
+
|
|
26
|
+
// Applies to the free-text feed fields only (title, trim). URLs, dealer_email and dealer_phone
|
|
27
|
+
// carry "/" ":" "@" "+" as load-bearing characters and must never be run through this.
|
|
28
|
+
export function normalizeFeedText(text: string): string {
|
|
29
|
+
return (text || '')
|
|
30
|
+
.replace(DISALLOWED_TEXT_CHARS, ' ')
|
|
31
|
+
.replace(/([.,\-/])\1+/g, '$1') // "L4H2 //Klimaanlage" -> "L4H2 /Klimaanlage"
|
|
32
|
+
.replace(/\s+/g, ' ')
|
|
33
|
+
.replace(EDGE_SEPARATORS, '');
|
|
34
|
+
}
|
|
35
|
+
|
|
17
36
|
// Parses a "Publish to web" Google Sheets CSV export (RFC4180-ish, quoted fields may
|
|
18
37
|
// contain commas/newlines) into row arrays, then maps rows to objects keyed by header.
|
|
19
38
|
export function parseCsvToObjects<T>(csv: string): T[] {
|