@bytebrand/export-cars 1.22.24 → 1.22.26

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.22.24",
3
+ "version": "1.22.26",
4
4
  "description": "",
5
5
  "author": "bytebrand",
6
6
  "license": "UNLICENSED",
@@ -16,6 +16,9 @@ export class FbXmlBuilder extends XMLBuilderBase {
16
16
  if (key === 'description') {
17
17
  return this.getDescriptionElement(key, data);
18
18
  }
19
+ if (key === 'additional_image_link' && Array.isArray(data)) {
20
+ return data.map((value: string) => this.getElement(key, value, true)).join('');
21
+ }
19
22
  if (Array.isArray(data)) {
20
23
  return this.getElementsArray(key, data);
21
24
  }
@@ -1,80 +1,80 @@
1
- import { XMLBuilderBase } from '@bytebrand/cronicle-helper';
2
- import { GoogleXmlItem, FbXmlItem, CriteoXmlItem } from '../interfaces';
3
-
4
- export class GoogleXmlBuilder extends XMLBuilderBase {
5
- async buildStart(url?: string): Promise<void> {
6
- await this.write(
7
- `<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:g="http://base.google.com/ns/1.0"><channel><title>Auto de feed</title><link>${url}</link>`,
8
- );
9
- }
10
-
11
- async addItem(item: FbXmlItem | GoogleXmlItem | CriteoXmlItem): Promise<void> {
12
- const listing: string = Object.entries(item)
13
- .map(([key, data]): string => {
14
- if (key === 'certification') {
15
- return this.getCertificationElement(key, data);
16
- }
17
-
18
- if (key === 'installment') {
19
- return this.getInstallmentElement(key, data);
20
- }
21
-
22
- if (key === 'vehicle_fulfillment') {
23
- return this.getVehicleFulfillmentElement(key, data);
24
- }
25
-
26
- if (['additional_image_link', 'vehicle_option'].includes(key)) {
27
- return data.map((value: string) => this.getElement(`g:${key}`, this.escapeXML(value))).join('');
28
- } else {
29
- return this.getElement(`g:${key}`, this.escapeXML(data));
30
- }
31
- })
32
- .join('');
33
-
34
- await this.write(`<item>${listing}</item>\n`);
35
- }
36
-
37
- async buildEnd(): Promise<void> {
38
- await this.write('</channel></rss>');
39
- await this.end();
40
- }
41
-
42
- private getVehicleFulfillmentElement(rootTag: string, data: {
43
- option: string;
44
- store_code: string;
45
- }): string {
46
- return `<g:${rootTag}>
47
- <g:option>${data.option}</g:option>
48
- <g:store_code>${data.store_code}</g:store_code>
49
- </g:${rootTag}>`;
50
- }
51
-
52
- private getCertificationElement(rootTag: string, data: Array<{
53
- certification_authority: string;
54
- certification_name: string;
55
- certification_code?: string;
56
- certification_value?: string;
57
- }>): string {
58
- return data.map(certification => `<g:${rootTag}>
59
- <g:certification_authority>${certification.certification_authority}</g:certification_authority>
60
- <g:certification_name>${certification.certification_name}</g:certification_name>
61
- <g:certification_value>${certification.certification_value}</g:certification_value>
62
- </g:${rootTag}>`).join('');
63
- }
64
-
65
- private getInstallmentElement(rootTag: string, data: { paybackPeriod: string; monthlyInstallment: string; apr?: string }): string {
66
- return `<g:${rootTag}>
67
- <g:months>${data.paybackPeriod}</g:months>
68
- <g:amount>${data.monthlyInstallment} EUR</g:amount>${data.apr ? `
69
- <g:apr>${data.apr}</g:apr>` : ''}
70
- </g:${rootTag}>`;
71
- }
72
-
73
- private escapeXML(str: string | null | undefined): string {
74
- return typeof str === 'string' ? str.replace(/&/g, '&amp;')
75
- .replace(/</g, '&lt;')
76
- .replace(/>/g, '&gt;')
77
- .replace(/"/g, '&quot;')
78
- .replace(/'/g, '&apos;') : str;
79
- }
80
- }
1
+ import { XMLBuilderBase } from '@bytebrand/cronicle-helper';
2
+ import { GoogleXmlItem, FbXmlItem, CriteoXmlItem } from '../interfaces';
3
+
4
+ export class GoogleXmlBuilder extends XMLBuilderBase {
5
+ async buildStart(url?: string): Promise<void> {
6
+ await this.write(
7
+ `<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:g="http://base.google.com/ns/1.0"><channel><title>Auto de feed</title><link>${url}</link>`,
8
+ );
9
+ }
10
+
11
+ async addItem(item: FbXmlItem | GoogleXmlItem | CriteoXmlItem): Promise<void> {
12
+ const listing: string = Object.entries(item)
13
+ .map(([key, data]): string => {
14
+ if (key === 'certification') {
15
+ return this.getCertificationElement(key, data);
16
+ }
17
+
18
+ if (key === 'installment') {
19
+ return this.getInstallmentElement(key, data);
20
+ }
21
+
22
+ if (key === 'vehicle_fulfillment') {
23
+ return this.getVehicleFulfillmentElement(key, data);
24
+ }
25
+
26
+ if (['additional_image_link', 'vehicle_option'].includes(key)) {
27
+ return data.map((value: string) => this.getElement(`g:${key}`, this.escapeXML(value))).join('');
28
+ } else {
29
+ return this.getElement(`g:${key}`, this.escapeXML(data));
30
+ }
31
+ })
32
+ .join('');
33
+
34
+ await this.write(`<item>${listing}</item>\n`);
35
+ }
36
+
37
+ async buildEnd(): Promise<void> {
38
+ await this.write('</channel></rss>');
39
+ await this.end();
40
+ }
41
+
42
+ private getVehicleFulfillmentElement(rootTag: string, data: {
43
+ option: string;
44
+ store_code: string;
45
+ }): string {
46
+ return `<g:${rootTag}>
47
+ <g:option>${data.option}</g:option>
48
+ <g:store_code>${data.store_code}</g:store_code>
49
+ </g:${rootTag}>`;
50
+ }
51
+
52
+ private getCertificationElement(rootTag: string, data: Array<{
53
+ certification_authority: string;
54
+ certification_name: string;
55
+ certification_code?: string;
56
+ certification_value?: string;
57
+ }>): string {
58
+ return data.map(certification => `<g:${rootTag}>
59
+ <g:certification_authority>${certification.certification_authority}</g:certification_authority>
60
+ <g:certification_name>${certification.certification_name}</g:certification_name>
61
+ <g:certification_value>${certification.certification_value}</g:certification_value>
62
+ </g:${rootTag}>`).join('');
63
+ }
64
+
65
+ private getInstallmentElement(rootTag: string, data: { paybackPeriod: string; monthlyInstallment: string; apr?: string }): string {
66
+ return `<g:${rootTag}>
67
+ <g:months>${data.paybackPeriod}</g:months>
68
+ <g:amount>${data.monthlyInstallment} EUR</g:amount>${data.apr ? `
69
+ <g:apr>${data.apr}</g:apr>` : ''}
70
+ </g:${rootTag}>`;
71
+ }
72
+
73
+ private escapeXML(str: string | null | undefined): string {
74
+ return typeof str === 'string' ? str.replace(/&/g, '&amp;')
75
+ .replace(/</g, '&lt;')
76
+ .replace(/>/g, '&gt;')
77
+ .replace(/"/g, '&quot;')
78
+ .replace(/'/g, '&apos;') : str;
79
+ }
80
+ }