@bytebrand/export-cars 1.26.38 → 1.26.40
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/criteo.config.d.ts +10 -0
- package/dist/configs/criteo.config.js +26 -1
- package/dist/configs/criteo.config.js.map +1 -1
- package/dist/exporters/criteo.exporter.js +27 -23
- package/dist/exporters/criteo.exporter.js.map +1 -1
- package/dist/interfaces/export-item.interface.d.ts +5 -5
- package/dist/services/criteo-feed-run.d.ts +76 -0
- package/dist/services/criteo-feed-run.js +186 -0
- package/dist/services/criteo-feed-run.js.map +1 -0
- package/dist/transformers/criteo.transformer.js +13 -8
- package/dist/transformers/criteo.transformer.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/docs/criteo/RUNBOOK.md +86 -0
- package/package.json +65 -65
- package/src/configs/criteo.config.ts +54 -17
- package/src/exporters/criteo.exporter.ts +63 -51
- package/src/interfaces/export-item.interface.ts +3 -3
- package/src/services/criteo-feed-run.ts +253 -0
- package/src/transformers/criteo.transformer.ts +22 -10
- package/test/criteo-feed-run.test.ts +365 -0
- package/test/criteo-mapping.test.ts +122 -0
- package/test/fixtures/criteo-20-cases.json +582 -0
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { Params } from '../interfaces/params.interface';
|
|
2
|
+
import { FeedGuardOptions } from '../services/feed-guard';
|
|
2
3
|
import { Config } from './config';
|
|
4
|
+
export declare const CRITEO_DEFAULTS: {
|
|
5
|
+
minSourceItems: number;
|
|
6
|
+
minPublishedItems: number;
|
|
7
|
+
maxDropPercent: number;
|
|
8
|
+
maxSourceAgeHours: number;
|
|
9
|
+
maxStaleHours: number;
|
|
10
|
+
};
|
|
3
11
|
export declare class CriteoConfig extends Config {
|
|
12
|
+
stateDir: string;
|
|
13
|
+
feedGuard: FeedGuardOptions;
|
|
4
14
|
constructor(params: Params);
|
|
5
15
|
}
|
|
@@ -1,15 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CriteoConfig = void 0;
|
|
3
|
+
exports.CriteoConfig = exports.CRITEO_DEFAULTS = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
4
5
|
const enums_1 = require("../enums");
|
|
5
6
|
const config_1 = require("./config");
|
|
7
|
+
const text = (value) => (typeof value === 'string' ? value.trim() : '');
|
|
8
|
+
const positiveNumber = (value, fallback) => {
|
|
9
|
+
const parsed = (0, lodash_1.toNumber)(text(value));
|
|
10
|
+
return text(value) && Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
|
|
11
|
+
};
|
|
12
|
+
exports.CRITEO_DEFAULTS = {
|
|
13
|
+
minSourceItems: 1000,
|
|
14
|
+
minPublishedItems: 500,
|
|
15
|
+
maxDropPercent: 20,
|
|
16
|
+
maxSourceAgeHours: 26,
|
|
17
|
+
maxStaleHours: 48,
|
|
18
|
+
};
|
|
6
19
|
class CriteoConfig extends config_1.Config {
|
|
20
|
+
stateDir;
|
|
21
|
+
feedGuard;
|
|
7
22
|
constructor(params) {
|
|
8
23
|
super(params);
|
|
9
24
|
this.campaign = enums_1.ExportType.CRITEO;
|
|
10
25
|
this.pathesConfig.localConvertedDirectory = `resources/${enums_1.ExportType.CRITEO}-export`;
|
|
26
|
+
this.stateDir = `resources/${enums_1.ExportType.CRITEO}-state`;
|
|
11
27
|
this.imageType = enums_1.ImageType.marketing;
|
|
12
28
|
this.marketingImageConfigId = this.environmentConfig[params.environment].criteoMarketingImagesConfigId;
|
|
29
|
+
this.feedGuard = {
|
|
30
|
+
stateDir: this.stateDir,
|
|
31
|
+
minSourceItems: positiveNumber(params.feedGuardMinSourceItems, exports.CRITEO_DEFAULTS.minSourceItems),
|
|
32
|
+
minPublishedItems: positiveNumber(params.feedGuardMinPublishedItems, exports.CRITEO_DEFAULTS.minPublishedItems),
|
|
33
|
+
maxDropPercent: positiveNumber(params.feedGuardMaxDropPercent, exports.CRITEO_DEFAULTS.maxDropPercent),
|
|
34
|
+
maxSourceAgeHours: positiveNumber(params.feedGuardMaxSourceAgeHours, exports.CRITEO_DEFAULTS.maxSourceAgeHours),
|
|
35
|
+
maxStaleHours: positiveNumber(params.feedGuardMaxStaleHours, exports.CRITEO_DEFAULTS.maxStaleHours),
|
|
36
|
+
acceptDrop: text(params.feedGuardAcceptDrop).toLowerCase() === 'true',
|
|
37
|
+
};
|
|
13
38
|
this.outputFiles = [
|
|
14
39
|
`${this.pathesConfig.localConvertedDirectory}/api_export_cars_${enums_1.ExportType.CRITEO}.${enums_1.FileType.XML}`,
|
|
15
40
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"criteo.config.js","sourceRoot":"","sources":["../../src/configs/criteo.config.ts"],"names":[],"mappings":";;;AAAA,oCAA4D;
|
|
1
|
+
{"version":3,"file":"criteo.config.js","sourceRoot":"","sources":["../../src/configs/criteo.config.ts"],"names":[],"mappings":";;;AAAA,mCAAkC;AAElC,oCAA4D;AAG5D,qCAAkC;AAElC,MAAM,IAAI,GAAG,CAAC,KAAc,EAAU,EAAE,CAAC,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAEzF,MAAM,cAAc,GAAG,CAAC,KAAc,EAAE,QAAgB,EAAU,EAAE;IAClE,MAAM,MAAM,GAAG,IAAA,iBAAQ,EAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACrC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC;AAClF,CAAC,CAAC;AAIW,QAAA,eAAe,GAAG;IAC7B,cAAc,EAAE,IAAI;IACpB,iBAAiB,EAAE,GAAG;IACtB,cAAc,EAAE,EAAE;IAClB,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AAM,IAAI,gBAAQ,CAAC,GAAG,EAAE;SACpG,CAAC;QACF,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACvB,CAAC;CACF;AAzBD,oCAyBC"}
|
|
@@ -14,7 +14,8 @@ const common_1 = require("@nestjs/common");
|
|
|
14
14
|
const core_1 = require("@nestjs/core");
|
|
15
15
|
const cronicle_helper_1 = require("@bytebrand/cronicle-helper");
|
|
16
16
|
const services_1 = require("../services");
|
|
17
|
-
const
|
|
17
|
+
const feed_guard_1 = require("../services/feed-guard");
|
|
18
|
+
const criteo_feed_run_1 = require("../services/criteo-feed-run");
|
|
18
19
|
const criteo_transformer_1 = require("../transformers/criteo.transformer");
|
|
19
20
|
let CriteoExporter = class CriteoExporter {
|
|
20
21
|
carService;
|
|
@@ -30,29 +31,32 @@ let CriteoExporter = class CriteoExporter {
|
|
|
30
31
|
this.moduleRef = moduleRef;
|
|
31
32
|
}
|
|
32
33
|
async export() {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
await
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
withoutImage += 1;
|
|
49
|
-
}
|
|
50
|
-
this.carService.counter.countCar(data.images);
|
|
51
|
-
}
|
|
34
|
+
const config = this.configService.config;
|
|
35
|
+
const [xmlFile] = config.outputFiles;
|
|
36
|
+
const transformer = await this.moduleRef.create(criteo_transformer_1.CriteoTransformer);
|
|
37
|
+
const run = new criteo_feed_run_1.CriteoFeedRun({
|
|
38
|
+
forEachChunk: fn => this.loaderService.process((chunk) => fn(chunk.data)),
|
|
39
|
+
filterCar: source => this.carService.filterCar(source, this.rulesService.rules),
|
|
40
|
+
transform: source => transformer.transform(source),
|
|
41
|
+
guard: new feed_guard_1.FeedGuard(config.feedGuard),
|
|
42
|
+
}, {
|
|
43
|
+
runId: config.runId,
|
|
44
|
+
domain: config.domain,
|
|
45
|
+
sourceDirectory: config.pathesConfig.localDirectory,
|
|
46
|
+
sourceBaseFileName: config.pathesConfig.baseFileName,
|
|
47
|
+
xmlFile,
|
|
48
|
+
stateDir: config.stateDir,
|
|
52
49
|
});
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
try {
|
|
51
|
+
const report = await run.run();
|
|
52
|
+
if (report.stale) {
|
|
53
|
+
console.log(`criteo feed STALE: last good file ${report.lastGoodAgeHours?.toFixed(1)} h old`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
cronicle_helper_1.LoggerService.exitError(`criteo feed not published: ${error?.message ?? error}`);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
56
60
|
}
|
|
57
61
|
};
|
|
58
62
|
exports.CriteoExporter = CriteoExporter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"criteo.exporter.js","sourceRoot":"","sources":["../../src/exporters/criteo.exporter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,uCAAyC;
|
|
1
|
+
{"version":3,"file":"criteo.exporter.js","sourceRoot":"","sources":["../../src/exporters/criteo.exporter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,uCAAyC;AAGzC,gEAA2D;AAE3D,0CAAqF;AACrF,uDAAmD;AACnD,iEAA6E;AAG7E,2EAAwE;AAQjE,IAAM,cAAc,GAApB,MAAM,cAAc;IAEjB;IACA;IACA;IACA;IACA;IALT,YACS,UAAsB,EACtB,aAA4B,EAC5B,YAA0B,EAC1B,aAA4B,EAC5B,SAAoB;QAJpB,eAAU,GAAV,UAAU,CAAY;QACtB,kBAAa,GAAb,aAAa,CAAe;QAC5B,iBAAY,GAAZ,YAAY,CAAc;QAC1B,kBAAa,GAAb,aAAa,CAAe;QAC5B,cAAS,GAAT,SAAS,CAAW;IACzB,CAAC;IAEL,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AK,EAAE,OAAO,IAAI,KAAK,EAAE,CAAC,CAAC;YACjF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;SAChB;IACF,CAAC;CACD,CAAA;AA3CY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;qCAGS,qBAAU;QACP,wBAAa;QACd,uBAAY;QACX,wBAAa;QACjB,gBAAS;GANjB,cAAc,CA2C1B"}
|
|
@@ -140,13 +140,13 @@ export interface CriteoXmlItem {
|
|
|
140
140
|
brand: any;
|
|
141
141
|
price: string;
|
|
142
142
|
sale_price: string;
|
|
143
|
-
energy_efficiency_class
|
|
143
|
+
energy_efficiency_class?: string;
|
|
144
144
|
color: string;
|
|
145
|
-
installment
|
|
146
|
-
paybackPeriod:
|
|
147
|
-
monthlyInstallment:
|
|
145
|
+
installment?: {
|
|
146
|
+
paybackPeriod: number;
|
|
147
|
+
monthlyInstallment: number;
|
|
148
148
|
};
|
|
149
|
-
custom_label_0
|
|
149
|
+
custom_label_0?: string;
|
|
150
150
|
}
|
|
151
151
|
export interface GoogleXmlItem {
|
|
152
152
|
id: string;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ImboImageResponseInterface } from '@bytebrand/chunkable';
|
|
2
|
+
import { DataSchemes } from '@bytebrand/car-schema';
|
|
3
|
+
import { CriteoXmlItem } from '../interfaces';
|
|
4
|
+
import { FeedGuard, LastGood } from './feed-guard';
|
|
5
|
+
export interface CriteoSourceCar {
|
|
6
|
+
car: DataSchemes.Car;
|
|
7
|
+
images: ImboImageResponseInterface[];
|
|
8
|
+
}
|
|
9
|
+
export declare enum CriteoExclusion {
|
|
10
|
+
noId = "no_id",
|
|
11
|
+
duplicateId = "duplicate_id",
|
|
12
|
+
filtered = "filtered",
|
|
13
|
+
notAvailable = "reserved_or_sold",
|
|
14
|
+
noPrice = "no_valid_price",
|
|
15
|
+
noImage = "no_marketing_image"
|
|
16
|
+
}
|
|
17
|
+
export interface CriteoRunDeps {
|
|
18
|
+
forEachChunk: (fn: (cars: CriteoSourceCar[]) => Promise<void>) => Promise<unknown>;
|
|
19
|
+
filterCar: (source: CriteoSourceCar) => boolean;
|
|
20
|
+
transform: (source: CriteoSourceCar) => Promise<CriteoXmlItem | null>;
|
|
21
|
+
guard: FeedGuard;
|
|
22
|
+
}
|
|
23
|
+
export interface CriteoRunOptions {
|
|
24
|
+
runId?: string;
|
|
25
|
+
domain: string;
|
|
26
|
+
sourceDirectory: string;
|
|
27
|
+
sourceBaseFileName: string;
|
|
28
|
+
xmlFile: string;
|
|
29
|
+
stateDir: string;
|
|
30
|
+
now?: () => Date;
|
|
31
|
+
}
|
|
32
|
+
export interface CriteoRunReport {
|
|
33
|
+
runId?: string;
|
|
34
|
+
startedAt: string;
|
|
35
|
+
finishedAt?: string;
|
|
36
|
+
durationMs?: number;
|
|
37
|
+
status: 'published' | 'blocked' | 'failed';
|
|
38
|
+
guard?: {
|
|
39
|
+
code: string;
|
|
40
|
+
message: string;
|
|
41
|
+
};
|
|
42
|
+
error?: string;
|
|
43
|
+
xmlFile: string;
|
|
44
|
+
source: {
|
|
45
|
+
files: number;
|
|
46
|
+
newestChunkAt: string | null;
|
|
47
|
+
ageHours: number | null;
|
|
48
|
+
cars: number;
|
|
49
|
+
};
|
|
50
|
+
items: number;
|
|
51
|
+
excluded: Record<string, number>;
|
|
52
|
+
withRate: number;
|
|
53
|
+
withoutEnergyClass: number;
|
|
54
|
+
ids: {
|
|
55
|
+
added: number;
|
|
56
|
+
removed: number;
|
|
57
|
+
kept: number;
|
|
58
|
+
removedSample: string[];
|
|
59
|
+
} | null;
|
|
60
|
+
lastGood: LastGood | null;
|
|
61
|
+
lastGoodAgeHours: number | null;
|
|
62
|
+
stale: boolean;
|
|
63
|
+
}
|
|
64
|
+
export declare class CriteoFeedRun {
|
|
65
|
+
private readonly deps;
|
|
66
|
+
private readonly options;
|
|
67
|
+
constructor(deps: CriteoRunDeps, options: CriteoRunOptions);
|
|
68
|
+
private now;
|
|
69
|
+
private get idsFile();
|
|
70
|
+
run(): Promise<CriteoRunReport>;
|
|
71
|
+
private exclusion;
|
|
72
|
+
private readPublishedIds;
|
|
73
|
+
private writePublishedIds;
|
|
74
|
+
private diffIds;
|
|
75
|
+
private writeReport;
|
|
76
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CriteoFeedRun = exports.CriteoExclusion = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
const google_xml_builder_1 = require("../formats/google-xml.builder");
|
|
8
|
+
const feed_guard_1 = require("./feed-guard");
|
|
9
|
+
var CriteoExclusion;
|
|
10
|
+
(function (CriteoExclusion) {
|
|
11
|
+
CriteoExclusion["noId"] = "no_id";
|
|
12
|
+
CriteoExclusion["duplicateId"] = "duplicate_id";
|
|
13
|
+
CriteoExclusion["filtered"] = "filtered";
|
|
14
|
+
CriteoExclusion["notAvailable"] = "reserved_or_sold";
|
|
15
|
+
CriteoExclusion["noPrice"] = "no_valid_price";
|
|
16
|
+
CriteoExclusion["noImage"] = "no_marketing_image";
|
|
17
|
+
})(CriteoExclusion || (exports.CriteoExclusion = CriteoExclusion = {}));
|
|
18
|
+
const NOT_AVAILABLE = ['selector_offerAvailability_reserved', 'selector_offerAvailability_sold'];
|
|
19
|
+
const HOUR_MS = 60 * 60 * 1000;
|
|
20
|
+
const PRICE = /^\d+(\.\d+)? EUR$/;
|
|
21
|
+
const increment = (counter, key) => {
|
|
22
|
+
counter[key] = (counter[key] ?? 0) + 1;
|
|
23
|
+
};
|
|
24
|
+
class CriteoFeedRun {
|
|
25
|
+
deps;
|
|
26
|
+
options;
|
|
27
|
+
constructor(deps, options) {
|
|
28
|
+
this.deps = deps;
|
|
29
|
+
this.options = options;
|
|
30
|
+
}
|
|
31
|
+
now() {
|
|
32
|
+
return this.options.now ? this.options.now() : new Date();
|
|
33
|
+
}
|
|
34
|
+
get idsFile() {
|
|
35
|
+
return (0, path_1.join)(this.options.stateDir, 'published-ids.json');
|
|
36
|
+
}
|
|
37
|
+
async run() {
|
|
38
|
+
const { guard } = this.deps;
|
|
39
|
+
const { xmlFile, runId } = this.options;
|
|
40
|
+
const startedAt = this.now();
|
|
41
|
+
const lastGood = await guard.readLastGood();
|
|
42
|
+
const report = {
|
|
43
|
+
runId,
|
|
44
|
+
startedAt: startedAt.toISOString(),
|
|
45
|
+
status: 'failed',
|
|
46
|
+
xmlFile,
|
|
47
|
+
source: { files: 0, newestChunkAt: null, ageHours: null, cars: 0 },
|
|
48
|
+
items: 0,
|
|
49
|
+
excluded: {},
|
|
50
|
+
withRate: 0,
|
|
51
|
+
withoutEnergyClass: 0,
|
|
52
|
+
ids: null,
|
|
53
|
+
lastGood,
|
|
54
|
+
lastGoodAgeHours: guard.staleHours(lastGood, startedAt),
|
|
55
|
+
stale: guard.isStale(lastGood, startedAt),
|
|
56
|
+
};
|
|
57
|
+
await guard.acquireLock(runId ?? 'local', startedAt);
|
|
58
|
+
const tmpFile = `${xmlFile}.tmp`;
|
|
59
|
+
try {
|
|
60
|
+
const snapshot = await (0, feed_guard_1.inspectSourceSnapshot)(this.options.sourceDirectory, this.options.sourceBaseFileName);
|
|
61
|
+
report.source.files = snapshot.files;
|
|
62
|
+
report.source.newestChunkAt = snapshot.newestMtime?.toISOString() ?? null;
|
|
63
|
+
report.source.ageHours = snapshot.newestMtime
|
|
64
|
+
? Number(((startedAt.getTime() - snapshot.newestMtime.getTime()) / HOUR_MS).toFixed(2))
|
|
65
|
+
: null;
|
|
66
|
+
guard.checkSource(snapshot, startedAt);
|
|
67
|
+
await fs_1.promises.mkdir((0, path_1.dirname)(xmlFile), { recursive: true });
|
|
68
|
+
await fs_1.promises.rm(tmpFile, { force: true });
|
|
69
|
+
const builder = new google_xml_builder_1.GoogleXmlBuilder(tmpFile);
|
|
70
|
+
await builder.buildStart(this.options.domain);
|
|
71
|
+
const seen = new Set();
|
|
72
|
+
const published = [];
|
|
73
|
+
await this.deps.forEachChunk(async (cars) => {
|
|
74
|
+
for (const source of cars) {
|
|
75
|
+
report.source.cars += 1;
|
|
76
|
+
const reason = this.exclusion(source, seen);
|
|
77
|
+
if (reason) {
|
|
78
|
+
increment(report.excluded, reason);
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const item = await this.deps.transform(source);
|
|
82
|
+
if (!item) {
|
|
83
|
+
increment(report.excluded, CriteoExclusion.noImage);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (!PRICE.test(item.price) || !PRICE.test(item.sale_price)) {
|
|
87
|
+
increment(report.excluded, CriteoExclusion.noPrice);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
await builder.addItem(item);
|
|
91
|
+
published.push(item.id);
|
|
92
|
+
report.items += 1;
|
|
93
|
+
if (item.installment) {
|
|
94
|
+
report.withRate += 1;
|
|
95
|
+
}
|
|
96
|
+
if (!item.energy_efficiency_class) {
|
|
97
|
+
report.withoutEnergyClass += 1;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
await builder.buildEnd();
|
|
102
|
+
const counts = { sourceItems: report.source.cars, publishedItems: report.items };
|
|
103
|
+
guard.checkCounts(counts, lastGood);
|
|
104
|
+
const previousIds = await this.readPublishedIds();
|
|
105
|
+
report.lastGood = await guard.publish(tmpFile, xmlFile, counts, this.now(), runId);
|
|
106
|
+
await this.writePublishedIds(published);
|
|
107
|
+
report.ids = this.diffIds(previousIds, published);
|
|
108
|
+
report.status = 'published';
|
|
109
|
+
report.lastGoodAgeHours = 0;
|
|
110
|
+
report.stale = false;
|
|
111
|
+
return report;
|
|
112
|
+
}
|
|
113
|
+
catch (error) {
|
|
114
|
+
if (error instanceof feed_guard_1.FeedGuardError) {
|
|
115
|
+
report.status = 'blocked';
|
|
116
|
+
report.guard = { code: error.code, message: error.message };
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
report.error = error?.message ?? String(error);
|
|
120
|
+
}
|
|
121
|
+
await fs_1.promises.rename(tmpFile, `${xmlFile}.rejected`).catch(() => undefined);
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
await this.writeReport(report, startedAt);
|
|
126
|
+
await guard.releaseLock();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
exclusion(source, seen) {
|
|
130
|
+
const id = (0, lodash_1.toString)((0, lodash_1.get)(source, 'car._id', ''));
|
|
131
|
+
if (!id) {
|
|
132
|
+
return CriteoExclusion.noId;
|
|
133
|
+
}
|
|
134
|
+
if (seen.has(id)) {
|
|
135
|
+
return CriteoExclusion.duplicateId;
|
|
136
|
+
}
|
|
137
|
+
seen.add(id);
|
|
138
|
+
if (!this.deps.filterCar(source)) {
|
|
139
|
+
return CriteoExclusion.filtered;
|
|
140
|
+
}
|
|
141
|
+
if (NOT_AVAILABLE.includes((0, lodash_1.toString)((0, lodash_1.get)(source.car, 'offer.offerAvailability', '')))) {
|
|
142
|
+
return CriteoExclusion.notAvailable;
|
|
143
|
+
}
|
|
144
|
+
const price = (0, lodash_1.toNumber)((0, lodash_1.get)(source.car, 'price.currentSalesPrice', null));
|
|
145
|
+
if (!Number.isFinite(price) || price <= 0) {
|
|
146
|
+
return CriteoExclusion.noPrice;
|
|
147
|
+
}
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
async readPublishedIds() {
|
|
151
|
+
try {
|
|
152
|
+
return JSON.parse(await fs_1.promises.readFile(this.idsFile, 'utf8'));
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
if (error?.code === 'ENOENT') {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
async writePublishedIds(ids) {
|
|
162
|
+
await fs_1.promises.mkdir(this.options.stateDir, { recursive: true });
|
|
163
|
+
await fs_1.promises.writeFile(`${this.idsFile}.tmp`, JSON.stringify(ids), 'utf8');
|
|
164
|
+
await fs_1.promises.rename(`${this.idsFile}.tmp`, this.idsFile);
|
|
165
|
+
}
|
|
166
|
+
diffIds(previous, current) {
|
|
167
|
+
if (!previous) {
|
|
168
|
+
return { added: current.length, removed: 0, kept: 0, removedSample: [] };
|
|
169
|
+
}
|
|
170
|
+
const before = new Set(previous);
|
|
171
|
+
const now = new Set(current);
|
|
172
|
+
const removed = previous.filter(id => !now.has(id));
|
|
173
|
+
const kept = current.filter(id => before.has(id)).length;
|
|
174
|
+
return { added: current.length - kept, removed: removed.length, kept, removedSample: removed.slice(0, 20) };
|
|
175
|
+
}
|
|
176
|
+
async writeReport(report, startedAt) {
|
|
177
|
+
const finishedAt = this.now();
|
|
178
|
+
report.finishedAt = finishedAt.toISOString();
|
|
179
|
+
report.durationMs = finishedAt.getTime() - startedAt.getTime();
|
|
180
|
+
await fs_1.promises.mkdir(this.options.stateDir, { recursive: true });
|
|
181
|
+
await fs_1.promises.writeFile((0, path_1.join)(this.options.stateDir, 'last-run-report.json'), JSON.stringify(report, null, 2), 'utf8');
|
|
182
|
+
console.log(`criteo feed report: ${JSON.stringify(report)}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.CriteoFeedRun = CriteoFeedRun;
|
|
186
|
+
//# sourceMappingURL=criteo-feed-run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"criteo-feed-run.js","sourceRoot":"","sources":["../../src/services/criteo-feed-run.ts"],"names":[],"mappings":";;;AAAA,2BAAoC;AACpC,+BAAqC;AACrC,mCAAiD;AAIjD,sEAAiE;AAEjE,6CAA0F;AAO1F,IAAY,eAOX;AAPD,WAAY,eAAe;IACzB,iCAAc,CAAA;IACd,+CAA4B,CAAA;IAC5B,wCAAqB,CAAA;IACrB,oDAAiC,CAAA;IACjC,6CAA0B,CAAA;IAC1B,iDAA8B,CAA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(car);
|
|
38
|
+
const installment = this.getInstallment(car);
|
|
37
39
|
return {
|
|
38
40
|
id: carId,
|
|
39
41
|
title: this.getTitle(car),
|
|
@@ -47,15 +49,16 @@ let CriteoTransformer = class CriteoTransformer {
|
|
|
47
49
|
brand: (0, lodash_1.get)(car, 'mainData.make', ''),
|
|
48
50
|
price: this.getRetailPrice(car),
|
|
49
51
|
sale_price: this.getPrice(car),
|
|
50
|
-
energy_efficiency_class:
|
|
52
|
+
...(energyClass ? { energy_efficiency_class: energyClass } : {}),
|
|
51
53
|
color: this.getColor(car),
|
|
52
|
-
installment
|
|
53
|
-
|
|
54
|
+
...(installment
|
|
55
|
+
? { installment, custom_label_0: `${installment.monthlyInstallment} EUR mtl.` }
|
|
56
|
+
: {}),
|
|
54
57
|
};
|
|
55
58
|
}
|
|
56
59
|
getTitle(car) {
|
|
57
60
|
const model = (0, lodash_1.toString)((0, lodash_1.get)(car, 'mainData.model', ''));
|
|
58
|
-
return (0, lodash_1.trim)((0, lodash_1.
|
|
61
|
+
return (0, lodash_1.trim)((0, lodash_1.join)([this.getBrand(car), model], ' '));
|
|
59
62
|
}
|
|
60
63
|
async getDescription(car) {
|
|
61
64
|
if (this.configService.config.isCriteo) {
|
|
@@ -129,14 +132,16 @@ let CriteoTransformer = class CriteoTransformer {
|
|
|
129
132
|
selector_energyEfficiencyClass_e: 'E',
|
|
130
133
|
selector_energyEfficiencyClass_f: 'F',
|
|
131
134
|
selector_energyEfficiencyClass_g: 'G',
|
|
132
|
-
selector_unknown: 'default',
|
|
133
135
|
};
|
|
134
|
-
const energyClass = (0, lodash_1.get)(car, 'environmentEmissions.wltpEnergyEfficiencyClass'
|
|
136
|
+
const energyClass = (0, lodash_1.get)(car, 'environmentEmissions.wltpEnergyEfficiencyClass');
|
|
135
137
|
return (0, lodash_1.get)(available, energyClass);
|
|
136
138
|
}
|
|
137
139
|
getInstallment(car) {
|
|
138
|
-
const monthlyInstallment = (0, lodash_1.round)((0, lodash_1.get)(car, 'rate.monthlyInstallment'
|
|
139
|
-
const paybackPeriod = (0, lodash_1.round)((0, lodash_1.get)(car, 'rate.paybackPeriod'
|
|
140
|
+
const monthlyInstallment = (0, lodash_1.round)(Number((0, lodash_1.get)(car, 'rate.monthlyInstallment')));
|
|
141
|
+
const paybackPeriod = (0, lodash_1.round)(Number((0, lodash_1.get)(car, 'rate.paybackPeriod')));
|
|
142
|
+
if (!(monthlyInstallment > 0) || !(paybackPeriod > 0)) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
140
145
|
return {
|
|
141
146
|
paybackPeriod,
|
|
142
147
|
monthlyInstallment,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"criteo.transformer.js","sourceRoot":"","sources":["../../src/transformers/criteo.transformer.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"criteo.transformer.js","sourceRoot":"","sources":["../../src/transformers/criteo.transformer.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAA0D;AAC1D,gEAAwF;AAExF,0DAA6D;AAC7D,oEAAwF;AACxF,2CAA4C;AAC5C,0CAAwE;AAIjE,IAAM,iBAAiB,GAAvB,MAAM,iBAAiB;IAIpB;IACA;IACA;IALD,UAAU,CAAqB;IAEvC,YACS,WAAwB,EACxB,aAA4B,EAC5B,YAA2B;QAF3B,gBAAW,GAAX,WAAW,CAAa;QACxB,kBAAa,GAAb,aAAa,CAAe;QAC5B,iBAAY,GAAZ,YAAY,CAAe;QAEnC,MAAM,IAAI,GAAG,EAAE,GAAG,sBAAE,EAAE,GAAG,kCAAc,EAAE,GAAG,wCAAoB,EAAE,CAAC;QACnE,IAAI,CAAC,UAAU,GAAG,IAAI,iCAAkB,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;IAID,KAAK,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,MAAM,EAAgD;QAC5E,MAAM,KAAK,GAAG,IAAA,iBAAQ,EAAC,IAAA,YAAG,EAAC,G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