@bytebrand/export-cars 1.26.31 → 1.26.32
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/configs/autouncle.config.d.ts +14 -0
- package/dist/configs/autouncle.config.js +36 -3
- package/dist/configs/autouncle.config.js.map +1 -1
- package/dist/configs/meinstadt.config.d.ts +15 -0
- package/dist/configs/meinstadt.config.js +42 -3
- package/dist/configs/meinstadt.config.js.map +1 -1
- package/dist/constants/autouncle.contants.d.ts +1 -3
- package/dist/constants/autouncle.contants.js +2 -4
- package/dist/constants/autouncle.contants.js.map +1 -1
- package/dist/exporters/autouncle.exporter.d.ts +3 -2
- package/dist/exporters/autouncle.exporter.js +45 -27
- package/dist/exporters/autouncle.exporter.js.map +1 -1
- package/dist/exporters/meinstadt.exporter.d.ts +3 -2
- package/dist/exporters/meinstadt.exporter.js +40 -23
- package/dist/exporters/meinstadt.exporter.js.map +1 -1
- package/dist/formats/autouncle-json.builder.js +1 -4
- package/dist/formats/autouncle-json.builder.js.map +1 -1
- package/dist/interfaces/export-item.interface.d.ts +8 -12
- package/dist/interfaces/params.interface.d.ts +6 -0
- package/dist/services/autouncle-feed-run.d.ts +66 -0
- package/dist/services/autouncle-feed-run.js +135 -0
- package/dist/services/autouncle-feed-run.js.map +1 -0
- package/dist/services/meinstadt-feed-run.d.ts +81 -0
- package/dist/services/meinstadt-feed-run.js +166 -0
- package/dist/services/meinstadt-feed-run.js.map +1 -0
- package/dist/transformers/autouncle.transformer.d.ts +38 -22
- package/dist/transformers/autouncle.transformer.js +156 -144
- package/dist/transformers/autouncle.transformer.js.map +1 -1
- package/dist/transformers/meinstadt.transformer.d.ts +17 -13
- package/dist/transformers/meinstadt.transformer.js +88 -61
- package/dist/transformers/meinstadt.transformer.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/docs/autouncle/AUDIT.md +97 -0
- package/docs/autouncle/PARTNER-QUESTIONS.md +53 -0
- package/docs/autouncle/RUNBOOK.md +64 -0
- package/docs/meinestadt/AUDIT.md +146 -0
- package/docs/meinestadt/PARTNER-QUESTIONS.md +54 -0
- package/docs/meinestadt/RUNBOOK.md +64 -0
- package/package.json +3 -2
- package/src/configs/autouncle.config.ts +51 -3
- package/src/configs/meinstadt.config.ts +57 -2
- package/src/constants/autouncle.contants.ts +2 -3
- package/src/exporters/autouncle.exporter.ts +59 -37
- package/src/exporters/meinstadt.exporter.ts +53 -32
- package/src/formats/autouncle-json.builder.ts +2 -4
- package/src/interfaces/export-item.interface.ts +15 -12
- package/src/interfaces/params.interface.ts +10 -0
- package/src/services/autouncle-feed-run.ts +197 -0
- package/src/services/meinstadt-feed-run.ts +240 -0
- package/src/transformers/autouncle.transformer.ts +217 -175
- package/src/transformers/meinstadt.transformer.ts +114 -68
- package/test/autouncle-feed-run.test.ts +256 -0
- package/test/autouncle-mapping.test.ts +225 -0
- package/test/fixtures/meinstadt.fixture.ts +87 -0
- package/test/meinstadt-feed-run.test.ts +288 -0
- package/test/meinstadt-mapping.test.ts +215 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AutouncleFeedRun = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const autouncle_json_builder_1 = require("../formats/autouncle-json.builder");
|
|
7
|
+
const autouncle_transformer_1 = require("../transformers/autouncle.transformer");
|
|
8
|
+
const feed_guard_1 = require("./feed-guard");
|
|
9
|
+
const increment = (counter, key) => {
|
|
10
|
+
counter[key] = (counter[key] ?? 0) + 1;
|
|
11
|
+
};
|
|
12
|
+
class AutouncleFeedRun {
|
|
13
|
+
deps;
|
|
14
|
+
options;
|
|
15
|
+
constructor(deps, options) {
|
|
16
|
+
this.deps = deps;
|
|
17
|
+
this.options = options;
|
|
18
|
+
}
|
|
19
|
+
now() {
|
|
20
|
+
return this.options.now ? this.options.now() : new Date();
|
|
21
|
+
}
|
|
22
|
+
async run() {
|
|
23
|
+
const { guard } = this.deps;
|
|
24
|
+
const { jsonFile, runId, dryRun } = this.options;
|
|
25
|
+
const startedAt = this.now();
|
|
26
|
+
const lastGood = await guard.readLastGood();
|
|
27
|
+
const report = {
|
|
28
|
+
runId,
|
|
29
|
+
mode: dryRun ? 'dry-run' : 'live',
|
|
30
|
+
startedAt: startedAt.toISOString(),
|
|
31
|
+
status: 'failed',
|
|
32
|
+
jsonFile,
|
|
33
|
+
source: { files: 0, newestChunkAt: null, cars: 0 },
|
|
34
|
+
items: 0,
|
|
35
|
+
dealers: 0,
|
|
36
|
+
excluded: {},
|
|
37
|
+
imagesPerItem: { min: null, max: null, total: 0 },
|
|
38
|
+
images: {},
|
|
39
|
+
lastGood,
|
|
40
|
+
lastGoodAgeHours: guard.staleHours(lastGood, startedAt),
|
|
41
|
+
stale: guard.isStale(lastGood, startedAt),
|
|
42
|
+
};
|
|
43
|
+
await guard.acquireLock(runId ?? 'local', startedAt);
|
|
44
|
+
const tmpFile = `${jsonFile}.tmp`;
|
|
45
|
+
try {
|
|
46
|
+
const snapshot = await (0, feed_guard_1.inspectSourceSnapshot)(this.options.sourceDirectory, this.options.sourceBaseFileName);
|
|
47
|
+
report.source.files = snapshot.files;
|
|
48
|
+
report.source.newestChunkAt = snapshot.newestMtime?.toISOString() ?? null;
|
|
49
|
+
guard.checkSource(snapshot, startedAt);
|
|
50
|
+
await fs_1.promises.mkdir((0, path_1.dirname)(jsonFile), { recursive: true });
|
|
51
|
+
await fs_1.promises.rm(tmpFile, { force: true });
|
|
52
|
+
const builder = new autouncle_json_builder_1.AutouncleJsonBuilder(tmpFile);
|
|
53
|
+
await builder.buildStart();
|
|
54
|
+
const seen = new Set();
|
|
55
|
+
const dealers = new Set();
|
|
56
|
+
let first = true;
|
|
57
|
+
await this.deps.forEachChunk(async (cars) => {
|
|
58
|
+
for (const source of cars) {
|
|
59
|
+
report.source.cars += 1;
|
|
60
|
+
const id = String(source?.car?._id ?? '');
|
|
61
|
+
if (id && seen.has(id)) {
|
|
62
|
+
increment(report.excluded, autouncle_transformer_1.AutouncleExclusion.duplicateId);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
seen.add(id);
|
|
66
|
+
if (!this.deps.filterCar(source)) {
|
|
67
|
+
increment(report.excluded, autouncle_transformer_1.AutouncleExclusion.filtered);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
const excluded = (0, autouncle_transformer_1.getAutouncleExclusion)(source.car);
|
|
71
|
+
if (excluded) {
|
|
72
|
+
increment(report.excluded, excluded);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const ownerId = String(source.car.metaData.ownerId).trim();
|
|
76
|
+
const address = await this.deps.dealerAddress(ownerId);
|
|
77
|
+
if (!address) {
|
|
78
|
+
increment(report.excluded, autouncle_transformer_1.AutouncleExclusion.noDealer);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const images = await this.deps.resolveImages(source);
|
|
82
|
+
const mapped = (0, autouncle_transformer_1.mapAutouncleItem)(source.car, { domain: this.options.domain, address, images, translate: this.deps.translate });
|
|
83
|
+
if (mapped.ok === false) {
|
|
84
|
+
increment(report.excluded, mapped.reason);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
await builder.addItem(mapped.item, first);
|
|
88
|
+
first = false;
|
|
89
|
+
dealers.add(ownerId);
|
|
90
|
+
this.count(report, mapped.item.images.length);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
await builder.buildEnd();
|
|
94
|
+
report.dealers = dealers.size;
|
|
95
|
+
report.images = this.deps.imageStats();
|
|
96
|
+
const counts = { sourceItems: report.source.cars, publishedItems: report.items };
|
|
97
|
+
guard.checkCounts(counts, lastGood);
|
|
98
|
+
report.lastGood = await guard.publish(tmpFile, jsonFile, counts, this.now(), runId);
|
|
99
|
+
report.status = 'published';
|
|
100
|
+
report.lastGoodAgeHours = 0;
|
|
101
|
+
report.stale = false;
|
|
102
|
+
return report;
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (error instanceof feed_guard_1.FeedGuardError) {
|
|
106
|
+
report.status = 'blocked';
|
|
107
|
+
report.guard = { code: error.code, message: error.message };
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
report.error = error?.message ?? String(error);
|
|
111
|
+
}
|
|
112
|
+
await fs_1.promises.rename(tmpFile, `${jsonFile}.rejected`).catch(() => undefined);
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
finally {
|
|
116
|
+
await this.writeReport(report);
|
|
117
|
+
await guard.releaseLock();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
count(report, images) {
|
|
121
|
+
report.items += 1;
|
|
122
|
+
const stats = report.imagesPerItem;
|
|
123
|
+
stats.min = stats.min === null ? images : Math.min(stats.min, images);
|
|
124
|
+
stats.max = stats.max === null ? images : Math.max(stats.max, images);
|
|
125
|
+
stats.total += images;
|
|
126
|
+
}
|
|
127
|
+
async writeReport(report) {
|
|
128
|
+
report.finishedAt = this.now().toISOString();
|
|
129
|
+
await fs_1.promises.mkdir(this.options.stateDir, { recursive: true });
|
|
130
|
+
await fs_1.promises.writeFile((0, path_1.join)(this.options.stateDir, 'last-run-report.json'), JSON.stringify(report, null, 2), 'utf8');
|
|
131
|
+
console.log(`autouncle feed report: ${JSON.stringify(report)}`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
exports.AutouncleFeedRun = AutouncleFeedRun;
|
|
135
|
+
//# sourceMappingURL=autouncle-feed-run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autouncle-feed-run.js","sourceRoot":"","sources":["../../src/services/autouncle-feed-run.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;AACpC,+BAAqC;AAIrC,8EAAyE;AACzE,iFAAsI;AACtI,6CAA0F;AAsD1F,MAAM,SAAS,GAAG,CAAC,OAA+B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AAO,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3D,MAAM,aAAE,CAAC,SAAS,CAAC,IAAA,WAAI,EAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,sBAAsB,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QACjH,OAAO,CAAC,GAAG,CAAC,0BAA0B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAClE,CAAC;CACF;AA7HD,4CA6HC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ImboImageResponseInterface } from '@bytebrand/chunkable';
|
|
2
|
+
import { DataSchemes } from '@bytebrand/car-schema';
|
|
3
|
+
import { FeedGuard, LastGood } from './feed-guard';
|
|
4
|
+
export interface MeinstadtSourceCar {
|
|
5
|
+
car: DataSchemes.Car;
|
|
6
|
+
images: ImboImageResponseInterface[];
|
|
7
|
+
}
|
|
8
|
+
export declare enum MeinstadtExclusion {
|
|
9
|
+
duplicateId = "duplicate_id",
|
|
10
|
+
filtered = "filtered",
|
|
11
|
+
noVehicleId = "no_vehicle_id",
|
|
12
|
+
noImage = "no_valid_image"
|
|
13
|
+
}
|
|
14
|
+
export declare class MeinstadtConfigError extends Error {
|
|
15
|
+
readonly code: string;
|
|
16
|
+
constructor(code: string, message: string);
|
|
17
|
+
}
|
|
18
|
+
export interface MeinstadtRunDeps {
|
|
19
|
+
forEachChunk: (fn: (cars: MeinstadtSourceCar[]) => Promise<void>) => Promise<unknown>;
|
|
20
|
+
filterCar: (source: MeinstadtSourceCar) => boolean;
|
|
21
|
+
resolveImages: (source: MeinstadtSourceCar) => Promise<string[]>;
|
|
22
|
+
imageStats: () => Record<string, number>;
|
|
23
|
+
equipment: (car: DataSchemes.Car) => Promise<string>;
|
|
24
|
+
zip: (jsonFile: string, zipFile: string) => Promise<void>;
|
|
25
|
+
guard: FeedGuard;
|
|
26
|
+
}
|
|
27
|
+
export interface MeinstadtRunOptions {
|
|
28
|
+
runId?: string;
|
|
29
|
+
dryRun: boolean;
|
|
30
|
+
cpc: string | null;
|
|
31
|
+
domain: string;
|
|
32
|
+
sourceDirectory: string;
|
|
33
|
+
sourceBaseFileName: string;
|
|
34
|
+
jsonFile: string;
|
|
35
|
+
zipFile: string;
|
|
36
|
+
stateDir: string;
|
|
37
|
+
translate?: (key: string) => string | undefined;
|
|
38
|
+
now?: () => Date;
|
|
39
|
+
}
|
|
40
|
+
export interface MeinstadtRunReport {
|
|
41
|
+
runId?: string;
|
|
42
|
+
mode: 'dry-run' | 'live';
|
|
43
|
+
startedAt: string;
|
|
44
|
+
finishedAt?: string;
|
|
45
|
+
status: 'published' | 'blocked' | 'failed';
|
|
46
|
+
guard?: {
|
|
47
|
+
code: string;
|
|
48
|
+
message: string;
|
|
49
|
+
};
|
|
50
|
+
error?: string;
|
|
51
|
+
cpc: string | null;
|
|
52
|
+
jsonFile: string;
|
|
53
|
+
zipFile: string;
|
|
54
|
+
source: {
|
|
55
|
+
files: number;
|
|
56
|
+
newestChunkAt: string | null;
|
|
57
|
+
cars: number;
|
|
58
|
+
};
|
|
59
|
+
items: number;
|
|
60
|
+
excluded: Record<string, number>;
|
|
61
|
+
accidentFree: Record<string, number>;
|
|
62
|
+
imagesPerItem: {
|
|
63
|
+
min: number | null;
|
|
64
|
+
max: number | null;
|
|
65
|
+
total: number;
|
|
66
|
+
};
|
|
67
|
+
images: Record<string, number>;
|
|
68
|
+
lastGood: LastGood | null;
|
|
69
|
+
lastGoodAgeHours: number | null;
|
|
70
|
+
stale: boolean;
|
|
71
|
+
}
|
|
72
|
+
export declare const zipSingleFile: (file: string, zipFile: string) => Promise<void>;
|
|
73
|
+
export declare class MeinstadtFeedRun {
|
|
74
|
+
private readonly deps;
|
|
75
|
+
private readonly options;
|
|
76
|
+
constructor(deps: MeinstadtRunDeps, options: MeinstadtRunOptions);
|
|
77
|
+
private now;
|
|
78
|
+
run(): Promise<MeinstadtRunReport>;
|
|
79
|
+
private count;
|
|
80
|
+
private writeReport;
|
|
81
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MeinstadtFeedRun = exports.zipSingleFile = exports.MeinstadtConfigError = exports.MeinstadtExclusion = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const meinstadt_json_builder_1 = require("../formats/meinstadt-json.builder");
|
|
7
|
+
const meinstadt_transformer_1 = require("../transformers/meinstadt.transformer");
|
|
8
|
+
const feed_guard_1 = require("./feed-guard");
|
|
9
|
+
var MeinstadtExclusion;
|
|
10
|
+
(function (MeinstadtExclusion) {
|
|
11
|
+
MeinstadtExclusion["duplicateId"] = "duplicate_id";
|
|
12
|
+
MeinstadtExclusion["filtered"] = "filtered";
|
|
13
|
+
MeinstadtExclusion["noVehicleId"] = "no_vehicle_id";
|
|
14
|
+
MeinstadtExclusion["noImage"] = "no_valid_image";
|
|
15
|
+
})(MeinstadtExclusion || (exports.MeinstadtExclusion = MeinstadtExclusion = {}));
|
|
16
|
+
class MeinstadtConfigError extends Error {
|
|
17
|
+
code;
|
|
18
|
+
constructor(code, message) {
|
|
19
|
+
super(`[meinstadt:${code}] ${message}`);
|
|
20
|
+
this.code = code;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.MeinstadtConfigError = MeinstadtConfigError;
|
|
24
|
+
const AdmZip = require('adm-zip');
|
|
25
|
+
const zipSingleFile = async (file, zipFile) => {
|
|
26
|
+
const archive = new AdmZip();
|
|
27
|
+
archive.addLocalFile(file);
|
|
28
|
+
archive.writeZip(zipFile);
|
|
29
|
+
};
|
|
30
|
+
exports.zipSingleFile = zipSingleFile;
|
|
31
|
+
const increment = (counter, key) => {
|
|
32
|
+
counter[key] = (counter[key] ?? 0) + 1;
|
|
33
|
+
};
|
|
34
|
+
class MeinstadtFeedRun {
|
|
35
|
+
deps;
|
|
36
|
+
options;
|
|
37
|
+
constructor(deps, options) {
|
|
38
|
+
this.deps = deps;
|
|
39
|
+
this.options = options;
|
|
40
|
+
}
|
|
41
|
+
now() {
|
|
42
|
+
return this.options.now ? this.options.now() : new Date();
|
|
43
|
+
}
|
|
44
|
+
async run() {
|
|
45
|
+
const { guard } = this.deps;
|
|
46
|
+
const { jsonFile, zipFile, stateDir, runId, dryRun, cpc } = this.options;
|
|
47
|
+
const startedAt = this.now();
|
|
48
|
+
const lastGood = await guard.readLastGood();
|
|
49
|
+
const report = {
|
|
50
|
+
runId,
|
|
51
|
+
mode: dryRun ? 'dry-run' : 'live',
|
|
52
|
+
startedAt: startedAt.toISOString(),
|
|
53
|
+
status: 'failed',
|
|
54
|
+
cpc,
|
|
55
|
+
jsonFile,
|
|
56
|
+
zipFile,
|
|
57
|
+
source: { files: 0, newestChunkAt: null, cars: 0 },
|
|
58
|
+
items: 0,
|
|
59
|
+
excluded: {},
|
|
60
|
+
accidentFree: {},
|
|
61
|
+
imagesPerItem: { min: null, max: null, total: 0 },
|
|
62
|
+
images: {},
|
|
63
|
+
lastGood,
|
|
64
|
+
lastGoodAgeHours: guard.staleHours(lastGood, startedAt),
|
|
65
|
+
stale: guard.isStale(lastGood, startedAt),
|
|
66
|
+
};
|
|
67
|
+
if (!dryRun && !cpc) {
|
|
68
|
+
report.error = 'cpc_missing';
|
|
69
|
+
await this.writeReport(report);
|
|
70
|
+
throw new MeinstadtConfigError('cpc_missing', 'live meinestadt feed needs a configured cpc (positive decimal, e.g. "0.99")');
|
|
71
|
+
}
|
|
72
|
+
await guard.acquireLock(runId ?? 'local', startedAt);
|
|
73
|
+
const tmpFile = `${jsonFile}.tmp`;
|
|
74
|
+
try {
|
|
75
|
+
const snapshot = await (0, feed_guard_1.inspectSourceSnapshot)(this.options.sourceDirectory, this.options.sourceBaseFileName);
|
|
76
|
+
report.source.files = snapshot.files;
|
|
77
|
+
report.source.newestChunkAt = snapshot.newestMtime?.toISOString() ?? null;
|
|
78
|
+
guard.checkSource(snapshot, startedAt);
|
|
79
|
+
await fs_1.promises.mkdir((0, path_1.dirname)(jsonFile), { recursive: true });
|
|
80
|
+
await fs_1.promises.rm(tmpFile, { force: true });
|
|
81
|
+
const builder = new meinstadt_json_builder_1.MeinstadtJsonBuilder(tmpFile);
|
|
82
|
+
await builder.buildStart();
|
|
83
|
+
const seen = new Set();
|
|
84
|
+
let first = true;
|
|
85
|
+
await this.deps.forEachChunk(async (cars) => {
|
|
86
|
+
for (const source of cars) {
|
|
87
|
+
report.source.cars += 1;
|
|
88
|
+
const id = String(source?.car?._id ?? '');
|
|
89
|
+
if (id && seen.has(id)) {
|
|
90
|
+
increment(report.excluded, MeinstadtExclusion.duplicateId);
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
seen.add(id);
|
|
94
|
+
if (!this.deps.filterCar(source)) {
|
|
95
|
+
increment(report.excluded, MeinstadtExclusion.filtered);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (!source.car?.metaData?.vehicleId) {
|
|
99
|
+
increment(report.excluded, MeinstadtExclusion.noVehicleId);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const images = await this.deps.resolveImages(source);
|
|
103
|
+
if (!images.length) {
|
|
104
|
+
increment(report.excluded, MeinstadtExclusion.noImage);
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
const item = (0, meinstadt_transformer_1.mapMeinstadtItem)(source.car, {
|
|
108
|
+
domain: this.options.domain,
|
|
109
|
+
cpc,
|
|
110
|
+
equipment: await this.deps.equipment(source.car),
|
|
111
|
+
images,
|
|
112
|
+
translate: this.options.translate,
|
|
113
|
+
});
|
|
114
|
+
await builder.addItem(item, first);
|
|
115
|
+
first = false;
|
|
116
|
+
this.count(report, item);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
await builder.buildEnd();
|
|
120
|
+
report.images = this.deps.imageStats();
|
|
121
|
+
const counts = { sourceItems: report.source.cars, publishedItems: report.items };
|
|
122
|
+
guard.checkCounts(counts, lastGood);
|
|
123
|
+
report.lastGood = await guard.publish(tmpFile, jsonFile, counts, this.now(), runId);
|
|
124
|
+
const zipTmp = zipFile.replace(/\.zip$/, '.tmp.zip');
|
|
125
|
+
await fs_1.promises.rm(zipTmp, { force: true });
|
|
126
|
+
await this.deps.zip(jsonFile, zipTmp);
|
|
127
|
+
await fs_1.promises.rename(zipTmp, zipFile);
|
|
128
|
+
report.status = 'published';
|
|
129
|
+
report.lastGoodAgeHours = 0;
|
|
130
|
+
report.stale = false;
|
|
131
|
+
return report;
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
if (error instanceof feed_guard_1.FeedGuardError) {
|
|
135
|
+
report.status = 'blocked';
|
|
136
|
+
report.guard = { code: error.code, message: error.message };
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
report.error = error?.message ?? String(error);
|
|
140
|
+
}
|
|
141
|
+
await fs_1.promises.rename(tmpFile, `${jsonFile}.rejected`).catch(() => undefined);
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
await this.writeReport(report);
|
|
146
|
+
await guard.releaseLock();
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
count(report, item) {
|
|
150
|
+
report.items += 1;
|
|
151
|
+
increment(report.accidentFree, String(item.accidentFree));
|
|
152
|
+
const n = item.images.length;
|
|
153
|
+
const stats = report.imagesPerItem;
|
|
154
|
+
stats.min = stats.min === null ? n : Math.min(stats.min, n);
|
|
155
|
+
stats.max = stats.max === null ? n : Math.max(stats.max, n);
|
|
156
|
+
stats.total += n;
|
|
157
|
+
}
|
|
158
|
+
async writeReport(report) {
|
|
159
|
+
report.finishedAt = this.now().toISOString();
|
|
160
|
+
await fs_1.promises.mkdir(this.options.stateDir, { recursive: true });
|
|
161
|
+
await fs_1.promises.writeFile((0, path_1.join)(this.options.stateDir, 'last-run-report.json'), JSON.stringify(report, null, 2), 'utf8');
|
|
162
|
+
console.log(`meinestadt feed report: ${JSON.stringify(report)}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.MeinstadtFeedRun = MeinstadtFeedRun;
|
|
166
|
+
//# sourceMappingURL=meinstadt-feed-run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meinstadt-feed-run.js","sourceRoot":"","sources":["../../src/services/meinstadt-feed-run.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;AACpC,+BAAqC;AAIrC,8EAAyE;AAEzE,iFAAyE;AACzE,6CAA0F;AAO1F,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,kDAA4B,CAAA;IAC5B,2CAAqB,CAAA;IACrB,mDAA6B,CAAA;IAC7B,gDAA0B,CAAA;AAC5B,CAAC,EALW,kBAAkB,kCAAlB,kBAAkB,QAK7B;AAED,MAAa,oBAAqB,SAAQ,KAAK;IACxB;IAArB,YAAqB,IAAY,EAAE,OAAe;QAChD,KAAK,CAAC,cAAc,IAAI,KAAK,OAAO,EAAE,CAAC,CAAC;QADrB,SAAI,GAAJ,IAAI,CAAQ;IAEjC,CAAC;CACF;AAJD,oDAIC;AAuDD,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAO3B,MAAM,aAAa,GAAG,KAAK,EAAE,IAAY,EAAE,OAAe,EAAiB,EAAE;IAClF,MAAM,OAAO,GAAG,IAAI,MAAM,EAAE,CAAC;IAC7B,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAC5B,CAAC,CAAC;AAJW,QAAA,aAAa,iBAIxB;AAEF,MAAM,SAAS,GAAG,CAAC,OAA+B,EAAE,GAAW,EAAE,EAAE;IACjE,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CAA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,CAAC,KAAK,IAAI,CAAC,CAAC;IACnB,CAAC;IAEO,KAAK,CAAC,WAAW,CAAC,MAA0B;QAClD,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,CAAC;QAC7C,MAAM,aAAE,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QAC3D,MAAM,aAAE,CAAC,SAAS,CAAC,IAAA,WAAI,EAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,sBAAsB,CAAC,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QACjH,OAAO,CAAC,GAAG,CAAC,2BAA2B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACnE,CAAC;CACF;AAvID,4CAuIC"}
|
|
@@ -1,31 +1,47 @@
|
|
|
1
1
|
import { DataSchemes } from '@bytebrand/car-schema';
|
|
2
|
-
import { ConfigService, ImagesService } from '../services';
|
|
3
2
|
import { AutouncleJsonItem } from '../interfaces';
|
|
4
|
-
import {
|
|
3
|
+
import { OpenAiImageSelection } from './openai-image-fields';
|
|
4
|
+
export declare enum AutouncleExclusion {
|
|
5
|
+
duplicateId = "duplicate_id",
|
|
6
|
+
filtered = "filtered",
|
|
7
|
+
noId = "no_id",
|
|
8
|
+
noDealer = "no_dealer",
|
|
9
|
+
notAvailable = "reserved_or_sold",
|
|
10
|
+
noPrice = "no_valid_price",
|
|
11
|
+
noImage = "no_valid_image"
|
|
12
|
+
}
|
|
13
|
+
export interface AutouncleAddress {
|
|
14
|
+
city: string;
|
|
15
|
+
addr1: string;
|
|
16
|
+
region: string;
|
|
17
|
+
postal_code: string;
|
|
18
|
+
}
|
|
19
|
+
export interface AutouncleMappingContext {
|
|
20
|
+
domain: string;
|
|
21
|
+
address: AutouncleAddress;
|
|
22
|
+
images: string[];
|
|
23
|
+
translate: (key: string) => string;
|
|
24
|
+
}
|
|
25
|
+
export type AutouncleMapResult = {
|
|
26
|
+
ok: true;
|
|
27
|
+
item: AutouncleJsonItem;
|
|
28
|
+
} | {
|
|
29
|
+
ok: false;
|
|
30
|
+
reason: AutouncleExclusion;
|
|
31
|
+
};
|
|
32
|
+
export declare const toAutouncleImages: (selection: OpenAiImageSelection, maxImages?: number) => string[];
|
|
33
|
+
export declare const getAutouncleYear: (firstRegistration: unknown, now?: Date) => string;
|
|
34
|
+
export declare const getAutouncleStatus: (firstRegistration: unknown) => 'Neuwagen' | 'Gebrauchtwagen';
|
|
35
|
+
export declare const getAutounclePrice: (value: unknown) => string | null;
|
|
36
|
+
export declare const getAutouncleExclusion: (car: DataSchemes.Car) => AutouncleExclusion | null;
|
|
37
|
+
export declare const mapAutouncleItem: (car: DataSchemes.Car, ctx: AutouncleMappingContext) => AutouncleMapResult;
|
|
5
38
|
export declare class AutouncleTransformer {
|
|
6
|
-
private configService;
|
|
7
|
-
private imageService;
|
|
8
39
|
private translator;
|
|
9
40
|
private postalCodesService;
|
|
10
|
-
constructor(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
images: ImboImageResponseInterface[];
|
|
14
|
-
metadata?: unknown;
|
|
15
|
-
owner: unknown;
|
|
16
|
-
}): Promise<AutouncleJsonItem>;
|
|
17
|
-
private getStatus;
|
|
18
|
-
private getYear;
|
|
19
|
-
private mapBodyStyle;
|
|
20
|
-
private mapFuel;
|
|
21
|
-
private mapTransmission;
|
|
22
|
-
private getPrice;
|
|
23
|
-
private getAddress;
|
|
41
|
+
constructor();
|
|
42
|
+
translate(key: string): string;
|
|
43
|
+
getAddress(owner: unknown): Promise<AutouncleAddress>;
|
|
24
44
|
private isEmptyLocation;
|
|
25
45
|
private isEmptyAddress;
|
|
26
|
-
private getCoords;
|
|
27
46
|
private getLocationByInfo;
|
|
28
|
-
private getExteriorColor;
|
|
29
|
-
private getMileage;
|
|
30
|
-
private has4WD;
|
|
31
47
|
}
|