@volontariapp/domain-event 3.4.0-snap-d42e2cf → 3.4.0-snap-a55d5a4
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/services/geocoding/strategy/google-maps.strategy.d.ts +3 -1
- package/dist/services/geocoding/strategy/google-maps.strategy.d.ts.map +1 -1
- package/dist/services/geocoding/strategy/google-maps.strategy.js +26 -10
- package/dist/services/geocoding/strategy/google-maps.strategy.js.map +1 -1
- package/package.json +6 -6
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { IGeocodingStrategy, GeocodeRequest, GeocodeResponse } from './geocoding-strategy.interface.js';
|
|
2
2
|
export declare class GoogleMapsStrategy implements IGeocodingStrategy {
|
|
3
3
|
private readonly apiKey;
|
|
4
|
+
private readonly skipInTestEnv;
|
|
4
5
|
private readonly logger;
|
|
5
6
|
private readonly baseUrl;
|
|
6
|
-
|
|
7
|
+
private static cache;
|
|
8
|
+
constructor(apiKey: string, skipInTestEnv?: boolean);
|
|
7
9
|
geocode(request: GeocodeRequest): Promise<GeocodeResponse | null>;
|
|
8
10
|
}
|
|
9
11
|
//# sourceMappingURL=google-maps.strategy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-maps.strategy.d.ts","sourceRoot":"","sources":["../../../../src/services/geocoding/strategy/google-maps.strategy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"google-maps.strategy.d.ts","sourceRoot":"","sources":["../../../../src/services/geocoding/strategy/google-maps.strategy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACd,eAAe,EAChB,MAAM,mCAAmC,CAAC;AAI3C,qBAAa,kBAAmB,YAAW,kBAAkB;IAMzD,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,aAAa;IANhC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoD;IAC3E,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAuD;IAC/E,OAAO,CAAC,MAAM,CAAC,KAAK,CAA6C;gBAG9C,MAAM,EAAE,MAAM,EACd,aAAa,GAAE,OAAe;IAO3C,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;CAqDxE"}
|
|
@@ -1,33 +1,49 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
1
2
|
import { Logger } from '@volontariapp/logger';
|
|
2
3
|
import { GEOCODING_FAILED } from '@volontariapp/errors-nest';
|
|
3
4
|
export class GoogleMapsStrategy {
|
|
4
5
|
apiKey;
|
|
6
|
+
skipInTestEnv;
|
|
5
7
|
logger = new Logger({ context: GoogleMapsStrategy.name });
|
|
6
8
|
baseUrl = 'https://maps.googleapis.com/maps/api/geocode/json';
|
|
7
|
-
|
|
9
|
+
static cache = new Map();
|
|
10
|
+
constructor(apiKey, skipInTestEnv = false) {
|
|
8
11
|
this.apiKey = apiKey;
|
|
12
|
+
this.skipInTestEnv = skipInTestEnv;
|
|
9
13
|
if (!this.apiKey) {
|
|
10
14
|
throw new Error('GoogleMapsStrategy requires a valid API key.');
|
|
11
15
|
}
|
|
12
16
|
}
|
|
13
17
|
async geocode(request) {
|
|
18
|
+
if (this.skipInTestEnv) {
|
|
19
|
+
return { lat: 48.8566, lng: 2.3522 };
|
|
20
|
+
}
|
|
14
21
|
try {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
url.searchParams.append('key', this.apiKey);
|
|
18
|
-
const response = await fetch(url.toString());
|
|
19
|
-
if (!response.ok) {
|
|
20
|
-
this.logger.error(`Google Maps API responded with status: ${String(response.status)}`);
|
|
21
|
-
throw GEOCODING_FAILED('Google Maps', response.status);
|
|
22
|
+
if (GoogleMapsStrategy.cache.has(request.address)) {
|
|
23
|
+
return GoogleMapsStrategy.cache.get(request.address);
|
|
22
24
|
}
|
|
23
|
-
const
|
|
25
|
+
const response = await axios.get(this.baseUrl, {
|
|
26
|
+
params: {
|
|
27
|
+
address: request.address,
|
|
28
|
+
key: this.apiKey,
|
|
29
|
+
},
|
|
30
|
+
timeout: 5000,
|
|
31
|
+
});
|
|
32
|
+
const data = response.data;
|
|
24
33
|
if (data.status === 'OK' && data.results.length > 0) {
|
|
25
34
|
const { lat, lng } = data.results[0].geometry.location;
|
|
26
|
-
|
|
35
|
+
const result = { lat, lng };
|
|
36
|
+
GoogleMapsStrategy.cache.set(request.address, result);
|
|
37
|
+
return result;
|
|
27
38
|
}
|
|
39
|
+
GoogleMapsStrategy.cache.set(request.address, null);
|
|
28
40
|
return null;
|
|
29
41
|
}
|
|
30
42
|
catch (error) {
|
|
43
|
+
if (axios.isAxiosError(error) && error.response) {
|
|
44
|
+
this.logger.error(`Google Maps API responded with status: ${String(error.response.status)}`);
|
|
45
|
+
throw GEOCODING_FAILED('Google Maps', error.response.status);
|
|
46
|
+
}
|
|
31
47
|
if (error instanceof Error && error.name === 'BadRequestError')
|
|
32
48
|
throw error;
|
|
33
49
|
const err = error;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"google-maps.strategy.js","sourceRoot":"","sources":["../../../../src/services/geocoding/strategy/google-maps.strategy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"google-maps.strategy.js","sourceRoot":"","sources":["../../../../src/services/geocoding/strategy/google-maps.strategy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAM1B,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,MAAM,OAAO,kBAAkB;IAMV;IACA;IANF,MAAM,GAAG,IAAI,MAAM,CAAC,EAAE,OAAO,EAAE,kBAAkB,CAAC,IAAI,EAAE,CAAC,CAAC;IAC1D,OAAO,GAAG,mDAAmD,CAAC;IACvE,MAAM,CAAC,KAAK,GAAG,IAAI,GAAG,EAAkC,CAAC;IAEjE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,MAAM,CAAC;YAChB,CAAC;YAED,kBAAkB,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACpD,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;gBAChD,IAAI,CAAC,MAAM,CAAC,KAAK,CACf,0CAA0C,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAC1E,CAAC;gBACF,MAAM,gBAAgB,CAAC,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAC/D,CAAC;YACD,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB;gBAAE,MAAM,KAAK,CAAC;YAE5E,MAAM,GAAG,GAAG,KAAc,CAAC;YAC3B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,8BAA8B,EAAE,GAAG,CAAC,CAAC;YACvD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@volontariapp/domain-event",
|
|
3
|
-
"version": "3.4.0-snap-
|
|
3
|
+
"version": "3.4.0-snap-a55d5a4",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"provenance": true
|
|
@@ -56,13 +56,13 @@
|
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@nestjs/common": "^11.0.1",
|
|
58
58
|
"@volontariapp/contracts": "4.0.14",
|
|
59
|
-
"@volontariapp/database": "3.3.1-snap-
|
|
59
|
+
"@volontariapp/database": "3.3.1-snap-a55d5a4",
|
|
60
60
|
"@volontariapp/errors": "0.6.0",
|
|
61
|
-
"@volontariapp/errors-nest": "0.13.0-snap-
|
|
61
|
+
"@volontariapp/errors-nest": "0.13.0-snap-a55d5a4",
|
|
62
62
|
"@volontariapp/logger": "0.2.5",
|
|
63
|
-
"@volontariapp/messaging": "2.7.0-snap-
|
|
64
|
-
"@volontariapp/outbox": "0.9.19-snap-
|
|
65
|
-
"@volontariapp/shared": "0.6.1-snap-
|
|
63
|
+
"@volontariapp/messaging": "2.7.0-snap-a55d5a4",
|
|
64
|
+
"@volontariapp/outbox": "0.9.19-snap-a55d5a4",
|
|
65
|
+
"@volontariapp/shared": "0.6.1-snap-a55d5a4",
|
|
66
66
|
"class-transformer": "^0.5.1"
|
|
67
67
|
}
|
|
68
68
|
}
|