airbyte-faros-destination 0.10.60 → 0.10.62

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.
@@ -1,11 +1,14 @@
1
+ import { AirbyteLogger } from 'faros-airbyte-cdk';
1
2
  import { FarosClient } from 'faros-js-client';
2
3
  import { DestinationRecord } from '../converter';
3
4
  export declare class LocationCollector {
5
+ private readonly logger?;
4
6
  private readonly farosClient?;
5
7
  private readonly locationsCache;
6
- constructor(resolveLocation: boolean, farosClient?: FarosClient);
8
+ constructor(resolveLocation: boolean, farosClient?: FarosClient, logger?: AirbyteLogger);
7
9
  collect(location?: string): Promise<{
8
10
  uid: string;
9
11
  } | null>;
10
12
  convertLocations(): DestinationRecord[];
13
+ private handleUncodedLocation;
11
14
  }
@@ -1,33 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LocationCollector = void 0;
4
+ const lodash_1 = require("lodash");
4
5
  class LocationCollector {
5
- constructor(resolveLocation, farosClient) {
6
+ constructor(resolveLocation, farosClient, logger) {
7
+ this.logger = logger;
6
8
  this.locationsCache = new Map();
7
9
  if (resolveLocation && farosClient) {
8
10
  this.farosClient = farosClient;
9
11
  }
10
12
  }
11
13
  async collect(location) {
12
- if (!location) {
14
+ var _a, _b;
15
+ const normalizedLocation = location === null || location === void 0 ? void 0 : location.trim();
16
+ if (!normalizedLocation) {
13
17
  return null;
14
18
  }
15
- if (this.locationsCache.has(location)) {
16
- return { uid: this.locationsCache.get(location).uid };
19
+ if (this.locationsCache.has(normalizedLocation)) {
20
+ const cached = this.locationsCache.get(normalizedLocation);
21
+ return { uid: cached.uid };
17
22
  }
18
23
  if (!this.farosClient) {
19
- // When we don't resolve locations, use the raw location string as the address
20
- const address = { uid: location, fullAddress: location };
21
- this.locationsCache.set(location, {
22
- uid: location,
23
- raw: location,
24
- address,
25
- });
26
- return { uid: location };
24
+ return this.handleUncodedLocation(normalizedLocation);
25
+ }
26
+ const data = await this.farosClient.geocode(normalizedLocation);
27
+ if (!((_a = data === null || data === void 0 ? void 0 : data[0]) === null || _a === void 0 ? void 0 : _a.uid)) {
28
+ (_b = this.logger) === null || _b === void 0 ? void 0 : _b.warn(`Invalid geocoding response for location '${normalizedLocation}'. ` +
29
+ 'Will use non-geocoded location.');
30
+ return this.handleUncodedLocation(normalizedLocation);
27
31
  }
28
- const data = await this.farosClient.geocode(location);
29
- const resolvedLocation = data[0]; // Resolving one location at a time
30
- this.locationsCache.set(location, resolvedLocation);
32
+ const resolvedLocation = data[0];
33
+ this.locationsCache.set(normalizedLocation, resolvedLocation);
31
34
  return { uid: resolvedLocation.uid };
32
35
  }
33
36
  convertLocations() {
@@ -35,37 +38,61 @@ class LocationCollector {
35
38
  const seenCoordinates = new Set();
36
39
  const records = [];
37
40
  Array.from(this.locationsCache.values()).forEach((location) => {
41
+ var _a;
38
42
  const address = location.address;
39
- if (!seenAddresses.has(address.uid)) {
40
- records.push({
41
- model: 'geo_Address',
42
- record: address,
43
- });
44
- seenAddresses.add(address.uid);
43
+ const isValidAddress = address === null || address === void 0 ? void 0 : address.uid;
44
+ if (isValidAddress) {
45
+ if (!seenAddresses.has(address.uid)) {
46
+ records.push({
47
+ model: 'geo_Address',
48
+ record: address,
49
+ });
50
+ seenAddresses.add(address.uid);
51
+ }
45
52
  }
46
- if (location.coordinates) {
47
- const coordinates = location.coordinates;
48
- const coordinatesKey = `${coordinates.lat}-${coordinates.lon}`;
53
+ const rawCoordinates = location.coordinates;
54
+ const lat = (rawCoordinates === null || rawCoordinates === void 0 ? void 0 : rawCoordinates.lat) ? (0, lodash_1.toNumber)(rawCoordinates.lat) : null;
55
+ const lon = (rawCoordinates === null || rawCoordinates === void 0 ? void 0 : rawCoordinates.lon) ? (0, lodash_1.toNumber)(rawCoordinates.lon) : null;
56
+ const coordinates = (0, lodash_1.isFinite)(lat) && (0, lodash_1.isFinite)(lon) ? { lat, lon } : null;
57
+ if (coordinates) {
58
+ const coordinatesKey = `${rawCoordinates.lat}:${rawCoordinates.lon}`;
49
59
  if (!seenCoordinates.has(coordinatesKey)) {
50
60
  records.push({
51
61
  model: 'geo_Coordinates',
52
- record: location.coordinates,
62
+ record: coordinates,
53
63
  });
54
64
  seenCoordinates.add(coordinatesKey);
55
65
  }
56
66
  }
67
+ else {
68
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn(`Invalid coordinates lat: ${rawCoordinates.lat} and lon: ` +
69
+ `${rawCoordinates.lon} for location '${location.raw}'.`);
70
+ }
71
+ // Create location record with optional address and coordinates
57
72
  records.push({
58
73
  model: 'geo_Location',
59
74
  record: {
60
75
  uid: location.uid,
61
76
  raw: location.raw,
62
- address: { uid: address.uid },
63
- coordinates: location.coordinates,
77
+ address: isValidAddress ? { uid: address.uid } : null,
78
+ coordinates: coordinates ? { lat, lon } : null,
64
79
  },
65
80
  });
66
81
  });
67
82
  return records;
68
83
  }
84
+ handleUncodedLocation(normalizedLocation) {
85
+ const address = {
86
+ uid: normalizedLocation,
87
+ fullAddress: normalizedLocation,
88
+ };
89
+ this.locationsCache.set(normalizedLocation, {
90
+ uid: normalizedLocation,
91
+ raw: normalizedLocation,
92
+ address,
93
+ });
94
+ return { uid: normalizedLocation };
95
+ }
69
96
  }
70
97
  exports.LocationCollector = LocationCollector;
71
98
  //# sourceMappingURL=geo.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"geo.js","sourceRoot":"","sources":["../../../src/converters/common/geo.ts"],"names":[],"mappings":";;;AAIA,MAAa,iBAAiB;IAI5B,YAAY,eAAwB,EAAE,WAAyB;QAF9C,mBAAc,GAAG,IAAI,GAAG,EAAoB,CAAC;QAG5D,IAAI,eAAe,IAAI,WAAW,EAAE,CAAC;YACnC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QACjC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,QAAiB;QAC7B,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,IAAI,C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