@bytebrand/export-cars 1.26.25 → 1.26.27

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.
Files changed (33) hide show
  1. package/README.md +30 -0
  2. package/dist/configs/config.d.ts +3 -1
  3. package/dist/configs/config.js +2 -0
  4. package/dist/configs/config.js.map +1 -1
  5. package/dist/configs/google.config.js +9 -0
  6. package/dist/configs/google.config.js.map +1 -1
  7. package/dist/export.command.js +1 -0
  8. package/dist/export.command.js.map +1 -1
  9. package/dist/exporters/google.exporter.js +9 -1
  10. package/dist/exporters/google.exporter.js.map +1 -1
  11. package/dist/interfaces/params.interface.d.ts +8 -0
  12. package/dist/services/feed-items-bigquery.writer.d.ts +17 -0
  13. package/dist/services/feed-items-bigquery.writer.js +96 -0
  14. package/dist/services/feed-items-bigquery.writer.js.map +1 -0
  15. package/dist/transformers/google-feed-envkv.d.ts +1 -0
  16. package/dist/transformers/google-feed-envkv.js +31 -17
  17. package/dist/transformers/google-feed-envkv.js.map +1 -1
  18. package/dist/transformers/google-feed-item-row.d.ts +25 -0
  19. package/dist/transformers/google-feed-item-row.js +37 -0
  20. package/dist/transformers/google-feed-item-row.js.map +1 -0
  21. package/dist/tsconfig.build.tsbuildinfo +1 -1
  22. package/package.json +3 -2
  23. package/schema/feed-items.json +122 -0
  24. package/src/configs/config.ts +97 -93
  25. package/src/configs/google.config.ts +26 -16
  26. package/src/export.command.ts +38 -37
  27. package/src/exporters/google.exporter.ts +56 -46
  28. package/src/interfaces/params.interface.ts +29 -17
  29. package/src/services/feed-items-bigquery.writer.ts +101 -0
  30. package/src/transformers/google-feed-envkv.ts +33 -15
  31. package/src/transformers/google-feed-item-row.ts +71 -0
  32. package/test/google-feed-envkv.test.ts +8 -3
  33. package/test/google-feed-item-row.test.ts +121 -0
package/README.md CHANGED
@@ -15,6 +15,36 @@
15
15
  <!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
16
16
  [![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
17
17
 
18
+ ## Google feed items in BigQuery (opt-in)
19
+
20
+ The Google export can record every item it writes to the XML in a BigQuery table, one row per item
21
+ per run, so a Merchant Center issue can be traced back to what was sent (EnVKV values, the field the
22
+ electric range came from, price, ...). Schema: `schema/feed-items.json`.
23
+
24
+ Job params (all three must be set, otherwise no BigQuery call is made):
25
+
26
+ | Param | Example |
27
+ |----------------------|------------------|
28
+ | `feedItemsBqProject` | `my-gcp-project` |
29
+ | `feedItemsBqDataset` | `feeds` |
30
+ | `feedItemsBqTable` | `feed_items` |
31
+
32
+ Credentials come from `credentials/google-cloud-project-id.json` in the plugin's working directory
33
+ (as in the import plugins). Rows are streamed in batches of 500 in the background; a BigQuery error
34
+ is logged and never fails the export (after 3 failed batches the run stops trying). `exportedAt` is
35
+ the start of the run, `partitionDay` its UTC day.
36
+
37
+ Create the table once, partitioned by day on `partitionDay`:
38
+
39
+ ```bash
40
+ bq mk --table \
41
+ --time_partitioning_field=partitionDay \
42
+ --time_partitioning_type=DAY \
43
+ --description="Items sent in the Google feed, one row per item per export run" \
44
+ my-gcp-project:feeds.feed_items \
45
+ schema/feed-items.json
46
+ ```
47
+
18
48
  ## Description
19
49
 
20
50
  [Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
@@ -1,5 +1,5 @@
1
1
  import { ExportType, ImageType } from '../enums';
2
- import { Params } from '../interfaces/params.interface';
2
+ import { FeedItemsBigQueryTarget, Params } from '../interfaces/params.interface';
3
3
  export declare class Config {
4
4
  apikey: string;
5
5
  campaign: string;
@@ -35,6 +35,8 @@ export declare class Config {
35
35
  dealersSpreadsheetId: string;
36
36
  dealersSpreadsheetTitle: string;
37
37
  metaPushPriorityCsvUrl: string;
38
+ runId?: string;
39
+ feedItemsBigQuery?: FeedItemsBigQueryTarget;
38
40
  protected environmentConfig: {
39
41
  develop: {
40
42
  domain: string;
@@ -29,6 +29,8 @@ class Config {
29
29
  dealersSpreadsheetId;
30
30
  dealersSpreadsheetTitle;
31
31
  metaPushPriorityCsvUrl;
32
+ runId;
33
+ feedItemsBigQuery;
32
34
  environmentConfig = {
33
35
  [enums_1.Environment.DEVELOP]: {
34
36
  domain: 'autode-dev.de',
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/configs/config.ts"],"names":[],"mappings":";;;AAAA,oCAA8D;AAG9D,MAAa,MAAM;IACjB,MAAM,CAAS;IACf,QAAQ,CAAS;IACjB,cAAc,CAAS;IACvB,sBAAsB,CAAS;IAC/B,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,QAAQ,CAAS;IACjB,YAAY,CAAS;IACrB,iBAAiB,CAAS;IAC1B,eAAe,CAAS;IACxB,SAAS,CAAY;IACrB,aAAa,CAAU;IACvB,QAAQ,CAAU;IAClB,QAAQ,CAAU;IAClB,UAAU,CAAa;IACvB,MAAM,CAAS;IACf,KAAK,CAIH;IAIF,oBAAoB,CAAU;IAC9B,YAAY,CAIV;IACF,WAAW,CAAW;IACtB,GAAG,CAAS;IACZ,oBAAoB,CAAS;IAC7B,uBAAuB,CAAS;IAChC,oBAAoB,CAAS;IAC7B,uBAAuB,CAAS;IAChC,sBAAsB,CAAS;IAErB,iBAAiB,GAAG;QAC5B,CAAC,mBAAW,CAAC,OAAO,CAAC,EAAE;YACrB,MAAM,EAAE,eAAe;YACvB,kBAAkB,EAAE,CAAC;YACrB,6BAA6B,EAAE,EAAE;YACjC,uBAAuB,EAAE,mBAAmB;YAC5C,eAAe,EAAE,YAAY;YAC7B,QAAQ,EAAE,yCAAyC;YACnD,YAAY,EAAE,8BAA8B;SAC7C;QACD,CAAC,mBAAW,CAAC,UAAU,CAAC,EAAE;YACxB,MAAM,EAAE,SAAS;YACjB,kBAAkB,EAAE,CAAC;YACrB,6BAA6B,EAAE,CAAC;YAChC,uBAAuB,EAAE,oBAAoB;YAC7C,eAAe,EAAE,QAAQ;YACzB,QA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M,EAAE,MAAM,CAAC,IAAI;SACpB,CAAC;QACF,IAAI,CAAC,YAAY,GAAG;YAClB,cAAc,EAAE,uBAAuB;YACvC,uBAAuB,EAAE,0BAA0B;YACnD,YAAY,EAAE,MAAM;SACrB,CAAC;IACJ,CAAC;CACF;AA7FD,wBA6FC"}
@@ -4,12 +4,21 @@ exports.GoogleConfig = void 0;
4
4
  const enums_1 = require("../enums");
5
5
  const feed_price_constants_1 = require("../constants/feed-price.constants");
6
6
  const config_1 = require("./config");
7
+ const trimmed = (value) => (typeof value === 'string' ? value.trim() : '');
7
8
  class GoogleConfig extends config_1.Config {
8
9
  constructor(params) {
9
10
  super(params);
10
11
  this.pathesConfig.localConvertedDirectory = `resources/${enums_1.ExportType.GOOGLE}-export`;
11
12
  this.imageType = enums_1.ImageType.default;
12
13
  this.maxCurrentSalesPrice = (0, feed_price_constants_1.resolveMaxFeedSalesPrice)(params.maxCurrentSalesPrice);
14
+ const feedItemsBigQuery = {
15
+ project: trimmed(params.feedItemsBqProject),
16
+ dataset: trimmed(params.feedItemsBqDataset),
17
+ table: trimmed(params.feedItemsBqTable),
18
+ };
19
+ if (feedItemsBigQuery.project && feedItemsBigQuery.dataset && feedItemsBigQuery.table) {
20
+ this.feedItemsBigQuery = feedItemsBigQuery;
21
+ }
13
22
  this.outputFiles = [
14
23
  `${this.pathesConfig.localConvertedDirectory}/api_export_cars_${enums_1.ExportType.GOOGLE}.${enums_1.FileType.XML}`,
15
24
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"google.config.js","sourceRoot":"","sources":["../../src/configs/google.config.ts"],"names":[],"mappings":";;;AAAA,oCAA4D;AAC5D,4EAA6E;AAE7E,qCAAkC;AAElC,MAAa,YAAa,SAAQ,eAAM;IACtC,YAAY,MAAc;QACxB,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,YAAY,CAAC,uBAAuB,GAAG,aAAa,kBAAU,CAAC,MAAM,SAAS,CAAC;QACpF,IAAI,CAAC,SAA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AAC;SAC5C;QACD,IAAI,CAAC,WAAW,GAAG;YACjB,GAAG,IAAI,CAAC,YAAY,CAAC,uBAAuB,oBAAoB,kBAAU,CAAC,MAAM,IAAI,gBAAQ,CAAC,GAAG,EAAE;SACpG,CAAC;IACJ,CAAC;CACF;AAlBD,oCAkBC"}
@@ -31,6 +31,7 @@ let ExportRunner = class ExportRunner extends nest_commander_1.CommandRunner {
31
31
  const input = JSON.parse(data);
32
32
  cronicle_helper_1.LoggerService.log(`Running job: ${input.id} - ${JSON.stringify(input)} \n`);
33
33
  this.configService.config = new export_schema_1.exportSchema[input.params.exportType].config(input.params);
34
+ this.configService.config.runId = input.id;
34
35
  const exporter = await this.moduleRef.create(export_schema_1.exportSchema[input.params.exportType].exporter);
35
36
  await exporter.export().catch(reject);
36
37
  resolve(rl.close());
@@ -1 +1 @@
1
- {"version":3,"file":"export.command.js","sourceRoot":"","sources":["../src/export.command.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,uCAA2C;AAC3C,mDAAwD;AACxD,yCAA2C;AAE3C,mDAA+C;AAC/C,uCAAyC;AAEzC,gEAA2D;AAMpD,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,8BAAa;IAEnC;IACA;IAFV,YACU,aAA4B,EAC5B,SAAoB;QAE5B,KAAK,EAAE,CAAC;QAHA,kBAAa,GAAb,aAAa,CAAe;QAC5B,cAAS,GAAT,SAAS,CAAW;IAG9B,CAAC;IAED,KAAK,CAAC,GAAG;QACP,MAAM,EAAE,GAAG,IAAA,0BAAe,EAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC;QACrD,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC1C,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,EAAE,IAAY,EAAE,EAAE;gBACnC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAU,CAAC;gBACxC,+BAAa,CA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../services");
17
17
  const google_transformer_1 = require("../transformers/google.transformer");
18
+ const google_feed_item_row_1 = require("../transformers/google-feed-item-row");
19
+ const feed_items_bigquery_writer_1 = require("../services/feed-items-bigquery.writer");
18
20
  const google_xml_builder_1 = require("../formats/google-xml.builder");
19
21
  let GoogleExporter = class GoogleExporter {
20
22
  carService;
@@ -36,16 +38,22 @@ let GoogleExporter = class GoogleExporter {
36
38
  const googleXmlBuilder = new google_xml_builder_1.GoogleXmlBuilder(fileName);
37
39
  await googleXmlBuilder.buildStart(this.configService.config.domain);
38
40
  const googleTransformer = await this.moduleRef.create(google_transformer_1.GoogleTransformer);
41
+ const { feedItemsBigQuery, runId } = this.configService.config;
42
+ const feedItemsWriter = feedItemsBigQuery ? new feed_items_bigquery_writer_1.FeedItemsBigQueryWriter(feedItemsBigQuery) : null;
43
+ const exportedAt = new Date();
39
44
  await this.loaderService.process(async (chunk) => {
40
45
  chunk.data = chunk.data.filter(car => this.carService.filterCar(car, this.rulesService.rules));
41
46
  for (const data of chunk.data) {
42
47
  const car = await googleTransformer.transform(data);
43
- if (car)
48
+ if (car) {
44
49
  await googleXmlBuilder.addItem(car);
50
+ feedItemsWriter?.add((0, google_feed_item_row_1.buildGoogleFeedItemRow)(data.car, car, runId, exportedAt));
51
+ }
45
52
  this.carService.counter.countCar(data.images);
46
53
  }
47
54
  });
48
55
  await googleXmlBuilder.buildEnd();
56
+ await feedItemsWriter?.close();
49
57
  console.log(this.carService.counter.getCountedCars());
50
58
  }
51
59
  };
@@ -1 +1 @@
1
- {"version":3,"file":"google.exporter.js","sourceRoot":"","sources":["../../src/exporters/google.exporter.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA4C;AAC5C,uCAAyC;AAEzC,gEAA2D;AAG3D,0CAAqF;AACrF,2EAAuE;AACvE,sEAAiE;AAI1D,IAAM,cAAc,GAApB,MAAM,cAAc;IAEf;IACA;IACA;IACA;IACA;IALV,YACU,UAAsB,EACtB,aAA4B,EAC5B,YAA0B,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,CAAC,CAAC;aAC/C;QACH,CAAC,CAAC,CAAC;QAEH,MAAM,gBAAgB,CAAC,QAAQ,EAAE,CAAC;QAClC,MAAM,eAAe,EAAE,KAAK,EAAE,CAAC;QAC/B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,cAAc,EAAE,CAAC,CAAC;IACxD,CAAC;CACF,CAAA;AAzCY,wCAAc;yBAAd,cAAc;IAD1B,IAAA,mBAAU,GAAE;qCAGW,qBAAU;QACP,wBAAa;QACd,uBAAY;QACX,wBAAa;QACjB,gBAAS;GANnB,cAAc,CAyC1B"}
@@ -11,4 +11,12 @@ export interface Params {
11
11
  ownerId?: string;
12
12
  metaPushPriorityCsvUrl?: string;
13
13
  maxCurrentSalesPrice?: string;
14
+ feedItemsBqProject?: string;
15
+ feedItemsBqDataset?: string;
16
+ feedItemsBqTable?: string;
17
+ }
18
+ export interface FeedItemsBigQueryTarget {
19
+ project: string;
20
+ dataset: string;
21
+ table: string;
14
22
  }
@@ -0,0 +1,17 @@
1
+ import { FeedItemsBigQueryTarget } from '../interfaces/params.interface';
2
+ import { FeedItemRow } from '../transformers/google-feed-item-row';
3
+ export declare class FeedItemsBigQueryWriter {
4
+ private target;
5
+ private logger;
6
+ private buffer;
7
+ private queue;
8
+ private failedBatches;
9
+ private insertedRows;
10
+ constructor(target: FeedItemsBigQueryTarget);
11
+ add(row: FeedItemRow): void;
12
+ close(): Promise<void>;
13
+ private get enabled();
14
+ private get tableName();
15
+ private flush;
16
+ private insert;
17
+ }
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FeedItemsBigQueryWriter = void 0;
4
+ const path_1 = require("path");
5
+ const bigquery_logger_1 = require("@bytebrand/bigquery-logger");
6
+ const BATCH_SIZE = 500;
7
+ const MAX_FAILED_BATCHES = 3;
8
+ const CLOSE_TIMEOUT_MS = 60000;
9
+ class FeedItemsBigQueryLogger extends bigquery_logger_1.BigQueryLogger {
10
+ async insertRows(rows) {
11
+ await this.client
12
+ .dataset(this.options.BigQueryDataset)
13
+ .table(this.options.BigQueryLogTable)
14
+ .insert(rows, { skipInvalidRows: true, ignoreUnknownValues: true });
15
+ }
16
+ }
17
+ class FeedItemsBigQueryWriter {
18
+ target;
19
+ logger;
20
+ buffer = [];
21
+ queue = Promise.resolve();
22
+ failedBatches = 0;
23
+ insertedRows = 0;
24
+ constructor(target) {
25
+ this.target = target;
26
+ try {
27
+ const credentials = require((0, path_1.join)(process.cwd(), 'credentials/google-cloud-project-id.json'));
28
+ this.logger = new FeedItemsBigQueryLogger(credentials, {
29
+ BigQueryProject: target.project,
30
+ BigQueryDataset: target.dataset,
31
+ BigQueryLogTable: target.table,
32
+ });
33
+ }
34
+ catch (e) {
35
+ console.log(`Feed items BigQuery disabled: ${String(e?.message || e).split('\n')[0]}`);
36
+ }
37
+ }
38
+ add(row) {
39
+ if (!this.enabled)
40
+ return;
41
+ this.buffer.push(row);
42
+ if (this.buffer.length >= BATCH_SIZE)
43
+ this.flush();
44
+ }
45
+ async close() {
46
+ this.flush();
47
+ let timer;
48
+ const timeout = new Promise((resolve) => {
49
+ timer = setTimeout(() => resolve('timeout'), CLOSE_TIMEOUT_MS);
50
+ });
51
+ const outcome = await Promise.race([this.queue.then(() => 'done'), timeout]);
52
+ if (timer)
53
+ clearTimeout(timer);
54
+ if (outcome === 'timeout')
55
+ console.error(`Feed items BigQuery: gave up waiting after ${CLOSE_TIMEOUT_MS} ms`);
56
+ if (this.logger) {
57
+ console.log(`Feed items BigQuery: ${this.insertedRows} rows to ${this.tableName}, ${this.failedBatches} failed batches`);
58
+ }
59
+ }
60
+ get enabled() {
61
+ return !!this.logger && this.failedBatches < MAX_FAILED_BATCHES;
62
+ }
63
+ get tableName() {
64
+ return `${this.target.project}.${this.target.dataset}.${this.target.table}`;
65
+ }
66
+ flush() {
67
+ if (!this.buffer.length)
68
+ return;
69
+ const rows = this.buffer;
70
+ this.buffer = [];
71
+ this.queue = this.queue.then(() => this.insert(rows));
72
+ }
73
+ async insert(rows) {
74
+ if (!this.enabled)
75
+ return;
76
+ try {
77
+ await this.logger.insertRows(rows);
78
+ this.insertedRows += rows.length;
79
+ }
80
+ catch (e) {
81
+ const rejected = e?.name === 'PartialFailureError' && Array.isArray(e.errors) ? e.errors : null;
82
+ const firstRowError = rejected?.[0]?.errors?.[0];
83
+ const detail = firstRowError ? ` (${firstRowError.reason}: ${firstRowError.message})` : '';
84
+ if (rejected) {
85
+ this.insertedRows += rows.length - rejected.length;
86
+ console.log(`Feed items BigQuery rejected ${rejected.length} of ${rows.length} rows${detail}`);
87
+ }
88
+ else {
89
+ this.failedBatches++;
90
+ console.log(`Feed items BigQuery insert of ${rows.length} rows failed: ${e?.message || e}`);
91
+ }
92
+ }
93
+ }
94
+ }
95
+ exports.FeedItemsBigQueryWriter = FeedItemsBigQueryWriter;
96
+ //# sourceMappingURL=feed-items-bigquery.writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feed-items-bigquery.writer.js","sourceRoot":"","sources":["../../src/services/feed-items-bigquery.writer.ts"],"names":[],"mappings":";;;AAAA,+BAA4B;AAC5B,gEAA4D;AAI5D,MAAM,UAAU,GAAG,GAAG,CAAC;AAEvB,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAE/B,MAAM,uBAAwB,SAAQ,gCAAc;IAClD,KAAK,CAAC,UAAU,CAAC,IAAmB;QAClC,MAAM,IAAI,CAAC,MAAM;aACd,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC;aACrC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC;aACpC,MAAM,CAAC,IAAI,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,CAAC,CAAC;IACxE,CAAC;CACF;AAKD,MAAa,uBAAuB;IAOd;IANZ,MAAM,CAA0B;I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I,CAAC,YAAY,IAAI,IAAI,CAAC,MAAM,CAAC;SAClC;QAAC,OAAO,CAAC,EAAE;YAGV,MAAM,QAAQ,GAAU,CAAC,EAAE,IAAI,KAAK,qBAAqB,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;YACvG,MAAM,aAAa,GAAG,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC;YACjD,MAAM,MAAM,GAAG,aAAa,CAAC,CAAC,CAAC,KAAK,aAAa,CAAC,MAAM,KAAK,aAAa,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3F,IAAI,QAAQ,EAAE;gBACZ,IAAI,CAAC,YAAY,IAAI,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;gBACnD,OAAO,CAAC,GAAG,CAAC,gCAAgC,QAAQ,CAAC,MAAM,OAAO,IAAI,CAAC,MAAM,QAAQ,MAAM,EAAE,CAAC,CAAC;aAChG;iBAAM;gBACL,IAAI,CAAC,aAAa,EAAE,CAAC;gBACrB,OAAO,CAAC,GAAG,CAAC,iCAAiC,IAAI,CAAC,MAAM,iBAAiB,CAAC,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC,CAAC;aAC7F;SACF;IACH,CAAC;CACF;AA9ED,0DA8EC"}
@@ -1,6 +1,7 @@
1
1
  import { DataSchemes } from '@bytebrand/car-schema';
2
2
  export declare function googleEngine(car: DataSchemes.Car): string;
3
3
  export declare function googleElectricRange(car: DataSchemes.Car): string | undefined;
4
+ export declare function googleElectricRangeSource(car: DataSchemes.Car): string | null;
4
5
  export declare function googleFuelConsumption(car: DataSchemes.Car): string | undefined;
5
6
  export declare function googleFuelConsumptionDischarged(car: DataSchemes.Car): string | undefined;
6
7
  export declare function googleEnergyConsumption(car: DataSchemes.Car): string | undefined;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.googleCo2 = exports.googleEnergyConsumption = exports.googleFuelConsumptionDischarged = exports.googleFuelConsumption = exports.googleElectricRange = exports.googleEngine = void 0;
3
+ exports.googleCo2 = exports.googleEnergyConsumption = exports.googleFuelConsumptionDischarged = exports.googleFuelConsumption = exports.googleElectricRangeSource = exports.googleElectricRange = exports.googleEngine = void 0;
4
4
  const lodash_1 = require("lodash");
5
5
  const GOOGLE_ENGINE = {
6
6
  selector_fuel_petrol: 'Gasoline',
@@ -26,26 +26,40 @@ function googleEngine(car) {
26
26
  return engine === 'Hybrid' && (0, lodash_1.get)(car, 'engineData.hybridPlugin') ? 'plug-in_hybrid' : engine;
27
27
  }
28
28
  exports.googleEngine = googleEngine;
29
- function googleElectricRange(car) {
30
- let range;
31
- if (isBev(car)) {
32
- range = positive((0, lodash_1.get)(car, 'battery.wltpRange')) ?? positive((0, lodash_1.get)(car, 'battery.batteryRangeElectric'));
33
- }
34
- else if (isPlugIn(car)) {
35
- range = positive((0, lodash_1.get)(car, 'battery.wltpTotalRange'))
36
- ?? positive((0, lodash_1.get)(car, 'battery.wltpRange'))
37
- ?? positive((0, lodash_1.get)(car, 'battery.batteryRangeElectric'));
29
+ const BEV_RANGE_FIELDS = ['battery.wltpRange', 'battery.batteryRangeElectric'];
30
+ const PLUG_IN_RANGE_FIELDS = ['battery.wltpTotalRange', 'battery.wltpRange', 'battery.batteryRangeElectric'];
31
+ const pickElectricRange = (car) => {
32
+ const fields = isBev(car) ? BEV_RANGE_FIELDS : isPlugIn(car) ? PLUG_IN_RANGE_FIELDS : [];
33
+ for (const field of fields) {
34
+ const range = positive((0, lodash_1.get)(car, field));
35
+ if (range)
36
+ return { field, range };
38
37
  }
39
- return range ? `${range}km` : undefined;
38
+ return undefined;
39
+ };
40
+ function googleElectricRange(car) {
41
+ const picked = pickElectricRange(car);
42
+ return picked ? `${picked.range}km` : undefined;
40
43
  }
41
44
  exports.googleElectricRange = googleElectricRange;
45
+ function googleElectricRangeSource(car) {
46
+ return pickElectricRange(car)?.field ?? null;
47
+ }
48
+ exports.googleElectricRangeSource = googleElectricRangeSource;
42
49
  const isConfirmedPlugIn = (car) => isPlugIn(car) && !!googleElectricRange(car);
43
50
  function googleFuelConsumption(car) {
44
51
  if (isBev(car))
45
52
  return undefined;
46
- const value = isConfirmedPlugIn(car)
47
- ? positive((0, lodash_1.get)(car, 'consumption.wltpWeightedCombined')) ?? positive((0, lodash_1.get)(car, 'consumption.consumptionCombined'))
48
- : positive((0, lodash_1.get)(car, 'consumption.consumptionCombined'));
53
+ let value;
54
+ if (isConfirmedPlugIn(car)) {
55
+ value = positive((0, lodash_1.get)(car, 'consumption.wltpWeightedCombined')) ?? positive((0, lodash_1.get)(car, 'consumption.consumptionCombined'));
56
+ }
57
+ else if (isPlugIn(car)) {
58
+ value = positive((0, lodash_1.get)(car, 'consumption.consumptionCombined'));
59
+ }
60
+ else {
61
+ value = positive((0, lodash_1.get)(car, 'consumption.wltpCombined')) ?? positive((0, lodash_1.get)(car, 'consumption.consumptionCombined'));
62
+ }
49
63
  return value ? `${value}l/100km` : undefined;
50
64
  }
51
65
  exports.googleFuelConsumption = googleFuelConsumption;
@@ -72,9 +86,9 @@ exports.googleEnergyConsumption = googleEnergyConsumption;
72
86
  function googleCo2(car) {
73
87
  if (isBev(car))
74
88
  return '0g/km';
75
- const value = isConfirmedPlugIn(car)
76
- ? positive((0, lodash_1.get)(car, 'environmentEmissions.wltpCo2')) ?? positive((0, lodash_1.get)(car, 'environmentEmissions.co2'))
77
- : positive((0, lodash_1.get)(car, 'environmentEmissions.co2'));
89
+ const value = isPlugIn(car) && !isConfirmedPlugIn(car)
90
+ ? positive((0, lodash_1.get)(car, 'environmentEmissions.co2'))
91
+ : positive((0, lodash_1.get)(car, 'environmentEmissions.wltpCo2')) ?? positive((0, lodash_1.get)(car, 'environmentEmissions.co2'));
78
92
  return value ? `${value}g/km` : undefined;
79
93
  }
80
94
  exports.googleCo2 = googleCo2;
@@ -1 +1 @@
1
- {"version":3,"file":"google-feed-envkv.js","sourceRoot":"","sources":["../../src/transformers/google-feed-envkv.ts"],"names":[],"mappings":";;;AAAA,mCAA6B;AAM7B,MAAM,aAAa,GAA2B;IAC5C,oBAAoB,EAAE,UAAU;IAChC,oBAAoB,EAAE,QAAQ;IAC9B,wBAAwB,EAAE,UAAU;IACpC,oCAAoC,EAAE,QAAQ;IAC9C,oCAAoC,EAAE,QAAQ;IAC9C,oBAAoB,EAAE,KAAK;IAC3B,wBAAwB,EAAE,aAAa;IACvC,qBAAqB,EAAE,OAAO;IAC9B,sBAAsB,EAAE,OAAO;IAC/B,gBAAgB,EAAE,OAAO;CAC1B,CAAC;AAEF,MAAM,YAAY,GAAG,CAAC,sCAAsC,EAAE,sCAAsC,CAAC,CAAC;AAEtG,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAsB,EAAE;IACtD,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACxB,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACrD,CAAC,CAAC;AAEF,MAAM,KAAK,GAAG,CAAC,GAAoB,EAAW,EAAE,CAAC,IAAA,YAAG,EAAC,GAAG,EAAE,kBAAkB,CAAC,KAAK,0BAA0B,CAAC;AAC7G,MAAM,QAAQ,GAAG,CAAC,GAAoB,EAAW,EAAE,CACjD,YAAY,CAAC,QAAQ,CAAC,IAAA,YAAG,EAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC,IAAI,CAAC,CAAC,IAAA,YAAG,EAAC,GAAG,EAAE,yBAAyB,CAAC,CAAC;AAE/F,SAAgB,YAAY,CAAC,GAAoB;IAC/C,MAAM,MAAM,GAAG,aAAa,CAAC,IAAA,YAAG,EAAC,GAAG,EAAE,kBAAkB,EAAE,kB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,CAAC;IAG/B,MAAM,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC;QACpD,CAAC,CAAC,QAAQ,CAAC,IAAA,YAAG,EAAC,GAAG,EAAE,0BAA0B,CAAC,CAAC;QAChD,CAAC,CAAC,QAAQ,CAAC,IAAA,YAAG,EAAC,GAAG,EAAE,8BAA8B,CAAC,CAAC,IAAI,QAAQ,CAAC,IAAA,YAAG,EAAC,GAAG,EAAE,0BAA0B,CAAC,CAAC,CAAC;IACzG,OAAO,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AAC5C,CAAC;AARD,8BAQC"}
@@ -0,0 +1,25 @@
1
+ import { DataSchemes } from '@bytebrand/car-schema';
2
+ import { GoogleXmlItem } from '../interfaces';
3
+ export interface FeedItemRow {
4
+ partitionDay: string;
5
+ exportedAt: string;
6
+ feed: string;
7
+ runId: string | null;
8
+ itemId: string;
9
+ vehicleId: string | null;
10
+ make: string | null;
11
+ model: string | null;
12
+ condition: string | null;
13
+ fuel: string | null;
14
+ hybridPlugin: boolean | null;
15
+ engine: string | null;
16
+ electricRange: string | null;
17
+ fuelConsumption: string | null;
18
+ fuelConsumptionDischarged: string | null;
19
+ energyConsumption: string | null;
20
+ co2Emissions: string | null;
21
+ rangeSourceField: string | null;
22
+ price: number | null;
23
+ availability: string | null;
24
+ }
25
+ export declare function buildGoogleFeedItemRow(car: DataSchemes.Car, item: GoogleXmlItem, runId: string | null, exportedAt: Date): FeedItemRow;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildGoogleFeedItemRow = void 0;
4
+ const lodash_1 = require("lodash");
5
+ const google_feed_envkv_1 = require("./google-feed-envkv");
6
+ const orNull = (value) => value === undefined || value === null || value === '' ? null : String(value);
7
+ const sentPrice = (price) => {
8
+ const n = parseFloat(price);
9
+ return Number.isFinite(n) ? n : null;
10
+ };
11
+ function buildGoogleFeedItemRow(car, item, runId, exportedAt) {
12
+ const hybridPlugin = (0, lodash_1.get)(car, 'engineData.hybridPlugin');
13
+ return {
14
+ partitionDay: exportedAt.toISOString().slice(0, 10),
15
+ exportedAt: exportedAt.toISOString(),
16
+ feed: 'google',
17
+ runId: orNull(runId),
18
+ itemId: String(item.id),
19
+ vehicleId: orNull((0, lodash_1.get)(car, 'metaData.vehicleId')),
20
+ make: orNull(item.brand),
21
+ model: orNull(item.model),
22
+ condition: orNull(item.condition),
23
+ fuel: orNull((0, lodash_1.get)(car, 'consumption.fuel')),
24
+ hybridPlugin: (0, lodash_1.isBoolean)(hybridPlugin) ? hybridPlugin : null,
25
+ engine: orNull(item.engine),
26
+ electricRange: orNull(item.electric_range),
27
+ fuelConsumption: orNull(item.fuel_consumption),
28
+ fuelConsumptionDischarged: orNull(item.fuel_consumption_discharged_battery),
29
+ energyConsumption: orNull(item.energy_consumption),
30
+ co2Emissions: orNull(item.co2_emissions),
31
+ rangeSourceField: item.electric_range ? (0, google_feed_envkv_1.googleElectricRangeSource)(car) : null,
32
+ price: sentPrice(item.price),
33
+ availability: orNull(item.availability),
34
+ };
35
+ }
36
+ exports.buildGoogleFeedItemRow = buildGoogleFeedItemRow;
37
+ //# sourceMappingURL=google-feed-item-row.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google-feed-item-row.js","sourceRoot":"","sources":["../../src/transformers/google-feed-item-row.ts"],"names":[],"mappings":";;;AAAA,mCAAwC;AAGxC,2DAAgE;AA4BhE,MAAM,MAAM,GAAG,CAAC,KAAc,EAAiB,EAAE,CAC/C,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAG/E,MAAM,SAAS,GAAG,CAAC,KAAyB,EAAiB,EAAE;IAC7D,MAAM,CAAC,GAAG,UAA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