@lyxa.ai/core 1.1.48 → 1.1.50
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/libraries/map/mapService.d.ts +2 -1
- package/dist/libraries/map/mapService.js +16 -1
- package/dist/libraries/map/mapService.js.map +1 -1
- package/dist/types/README.md +1 -1
- package/dist/types/package.json +1 -1
- package/dist/types/utilities/shared/currency.js +1 -1
- package/dist/types/utilities/shared/currency.js.map +1 -1
- package/dist/utilities/shared/currency.js +1 -1
- package/dist/utilities/shared/currency.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,8 @@ import { IMapService, ICoordinate, IDistanceInfo, IWaypointDistanceInfo } from '
|
|
|
2
2
|
export declare class MapService {
|
|
3
3
|
private service;
|
|
4
4
|
constructor(service: IMapService);
|
|
5
|
-
|
|
5
|
+
calculateHaversineDistance(coord1: [number, number], coord2: [number, number]): number;
|
|
6
|
+
calculateDistanceBetweenCoordinates(coord1: [number, number], coord2: [number, number]): Promise<number>;
|
|
6
7
|
getDistanceInfo(origin: ICoordinate, destination: ICoordinate): Promise<IDistanceInfo>;
|
|
7
8
|
getWaypointsDistanceInfo(origin: ICoordinate, destination: ICoordinate, waypoints: Array<ICoordinate>): Promise<IWaypointDistanceInfo>;
|
|
8
9
|
}
|
|
@@ -16,7 +16,7 @@ let MapService = class MapService {
|
|
|
16
16
|
constructor(service) {
|
|
17
17
|
this.service = service;
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
calculateHaversineDistance(coord1, coord2) {
|
|
20
20
|
const [lat1, lon1] = coord1;
|
|
21
21
|
const [lat2, lon2] = coord2;
|
|
22
22
|
const R = 6371;
|
|
@@ -30,6 +30,21 @@ let MapService = class MapService {
|
|
|
30
30
|
const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
|
31
31
|
return R * c;
|
|
32
32
|
}
|
|
33
|
+
async calculateDistanceBetweenCoordinates(coord1, coord2) {
|
|
34
|
+
const [lat1, lon1] = coord1;
|
|
35
|
+
const [lat2, lon2] = coord2;
|
|
36
|
+
try {
|
|
37
|
+
const distanceInfo = await this.service.getDistanceInfo({ latitude: lat1, longitude: lon1 }, { latitude: lat2, longitude: lon2 });
|
|
38
|
+
if (distanceInfo && distanceInfo.distance) {
|
|
39
|
+
return distanceInfo.distance.value / 1000;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error(`Error fetching distance info: ${error}`);
|
|
44
|
+
}
|
|
45
|
+
console.log('Maps API failed. Falling back to Haversine calculation.');
|
|
46
|
+
return this.calculateHaversineDistance(coord1, coord2);
|
|
47
|
+
}
|
|
33
48
|
async getDistanceInfo(origin, destination) {
|
|
34
49
|
return await this.service.getDistanceInfo(origin, destination);
|
|
35
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapService.js","sourceRoot":"/","sources":["libraries/map/mapService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAiC;AAI1B,IAAM,UAAU,GAAhB,MAAM,UAAU;IACF;IAApB,YAAoB,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa;IAAG,CAAC;IAUrC,
|
|
1
|
+
{"version":3,"file":"mapService.js","sourceRoot":"/","sources":["libraries/map/mapService.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mCAAiC;AAI1B,IAAM,UAAU,GAAhB,MAAM,UAAU;IACF;IAApB,YAAoB,OAAoB;QAApB,YAAO,GAAP,OAAO,CAAa;IAAG,CAAC;IAUrC,0BAA0B,CAAC,MAAwB,EAAE,MAAwB;QACnF,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC;QAC5B,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,MAAM,CAAC;QAG5B,MAAM,CAAC,GAAG,IAAI,CAAC;QAGf,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,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gBAC3C,OAAO,YAAY,CAAC,QAAQ,CAAC,KAAK,GAAG,IAAI,CAAC;YAC3C,CAAC;QACF,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,OAAO,CAAC,KAAK,CAAC,iCAAiC,KAAK,EAAE,CAAC,CAAC;QACzD,CAAC;QAGD,OAAO,CAAC,GAAG,CAAC,yDAAyD,CAAC,CAAC;QACvE,OAAO,IAAI,CAAC,0BAA0B,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;IASD,KAAK,CAAC,eAAe,CAAC,MAAmB,EAAE,WAAwB;QAClE,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAChE,CAAC;IAUD,KAAK,CAAC,wBAAwB,CAC7B,MAAmB,EACnB,WAAwB,EACxB,SAA6B;QAE7B,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IACpF,CAAC;CACD,CAAA;AA5FY,gCAAU;qBAAV,UAAU;IADtB,IAAA,gBAAO,GAAE;;GACG,UAAU,CA4FtB","sourcesContent":["import { Service } from 'typedi';\nimport { IMapService, ICoordinate, IDistanceInfo, IWaypointDistanceInfo } from './interfaces/IMapService';\n\n@Service()\nexport class MapService {\n\tconstructor(private service: IMapService) {}\n\n\t/**\n\t * Calculates the distance between two coordinates in kilometers\n\t * using the Haversine formula\n\t *\n\t * @param coord1 - First coordinate [latitude, longitude]\n\t * @param coord2 - Second coordinate [latitude, longitude]\n\t * @returns Distance in kilometers\n\t */\n\tpublic calculateHaversineDistance(coord1: [number, number], coord2: [number, number]): number {\n\t\tconst [lat1, lon1] = coord1;\n\t\tconst [lat2, lon2] = coord2;\n\n\t\t// Earth radius in kilometers\n\t\tconst R = 6371;\n\n\t\t// Convert degrees to radians\n\t\tconst dLat = ((lat2 - lat1) * Math.PI) / 180;\n\t\tconst dLon = ((lon2 - lon1) * Math.PI) / 180;\n\n\t\tconst a =\n\t\t\tMath.sin(dLat / 2) * Math.sin(dLat / 2) +\n\t\t\tMath.cos((lat1 * Math.PI) / 180) *\n\t\t\t\tMath.cos((lat2 * Math.PI) / 180) *\n\t\t\t\tMath.sin(dLon / 2) *\n\t\t\t\tMath.sin(dLon / 2);\n\n\t\tconst c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));\n\n\t\treturn R * c;\n\t}\n\n\t/**\n\t * Calculates the distance between two coordinates in kilometers\n\t * using the Haversine formula\n\t *\n\t * @param coord1 - First coordinate [latitude, longitude]\n\t * @param coord2 - Second coordinate [latitude, longitude]\n\t * @returns Distance in kilometers\n\t */\n\tpublic async calculateDistanceBetweenCoordinates(\n\t\tcoord1: [number, number],\n\t\tcoord2: [number, number]\n\t): Promise<number> {\n\t\tconst [lat1, lon1] = coord1;\n\t\tconst [lat2, lon2] = coord2;\n\n\t\ttry {\n\t\t\tconst distanceInfo = await this.service.getDistanceInfo(\n\t\t\t\t{ latitude: lat1, longitude: lon1 },\n\t\t\t\t{ latitude: lat2, longitude: lon2 }\n\t\t\t);\n\t\t\tif (distanceInfo && distanceInfo.distance) {\n\t\t\t\treturn distanceInfo.distance.value / 1000; // Convert meters to kilometers\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tconsole.error(`Error fetching distance info: ${error}`);\n\t\t}\n\n\t\t// Fallback to Haversine formula if API call fails\n\t\tconsole.log('Maps API failed. Falling back to Haversine calculation.');\n\t\treturn this.calculateHaversineDistance(coord1, coord2);\n\t}\n\n\t/**\n\t * Get the distance and driving duration between two locations\n\t *\n\t * @param origin - Origin coordinate\n\t * @param destination - Destination coordinate\n\t * @returns Distance and duration\n\t */\n\tasync getDistanceInfo(origin: ICoordinate, destination: ICoordinate): Promise<IDistanceInfo> {\n\t\treturn await this.service.getDistanceInfo(origin, destination);\n\t}\n\n\t/**\n\t * Get the distance and driving duration between two locations\n\t *\n\t * @param origin - Origin coordinate\n\t * @param destination - Destination coordinate\n\t * @param waypoints - Coordinates of intermediary waypoints\n\t * @returns Distance, duration, and polyline of each leg and the whole journey\n\t */\n\tasync getWaypointsDistanceInfo(\n\t\torigin: ICoordinate,\n\t\tdestination: ICoordinate,\n\t\twaypoints: Array<ICoordinate>\n\t): Promise<IWaypointDistanceInfo> {\n\t\treturn await this.service.getWaypointsDistanceInfo(origin, destination, waypoints);\n\t}\n}\n"]}
|
package/dist/types/README.md
CHANGED
package/dist/types/package.json
CHANGED
|
@@ -12,7 +12,7 @@ const roundCurrencySync = (amount, roundingFactor) => {
|
|
|
12
12
|
return 0;
|
|
13
13
|
}
|
|
14
14
|
const decimals = (roundingFactor.toString().split('.')[1] || '').length;
|
|
15
|
-
const rounded = Math.round(amount / roundingFactor) * roundingFactor;
|
|
15
|
+
const rounded = Math.round((amount + Number.EPSILON) / roundingFactor) * roundingFactor;
|
|
16
16
|
return Number(rounded.toFixed(decimals));
|
|
17
17
|
};
|
|
18
18
|
exports.roundCurrencySync = roundCurrencySync;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.js","sourceRoot":"/","sources":["utilities/shared/currency.ts"],"names":[],"mappings":";;;AACa,QAAA,mBAAmB,GAAG,IAAI,CAAC;AAC3B,QAAA,wBAAwB,GAAG,IAAI,CAAC;AAGtC,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAE,cAAsB,EAAU,EAAE;IACnF,IACC,OAAO,MAAM,KAAK,QAAQ;QAC1B,KAAK,CAAC,MAAM,CAAC;QACb,OAAO,cAAc,KAAK,QAAQ;QAClC,cAAc,IAAI,CAAC;QACnB,MAAM,KAAK,CAAC,EACX,CAAC;QACF,OAAO,CAAC,CAAC;IACV,CAAC;IAED,MAAM,QAAQ,GAAG,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;IACxE,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,cAAc,CAAC,GAAG,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"currency.js","sourceRoot":"/","sources":["utilities/shared/currency.ts"],"names":[],"mappings":";;;AACa,QAAA,mBAAmB,GAAG,IAAI,CAAC;AAC3B,QAAA,wBAAwB,GAAG,IAAI,CAAC;AAGtC,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAE,cAAsB,EAAU,EAAE;IACnF,IACC,OAAO,MAAM,KAAK,QAAQ;QAC1B,KAAK,CAAC,MAAM,CAAC;QACb,OAAO,cAAc,KAAK,QAAQ;QAClC,cAAc,IAAI,CAAC;QACnB,MAAM,KAAK,CAAC,EACX,CAAC;QACF,OAAO,CAAC,CAAC;IACV,CAAC;IAED,MAAM,QAAQ,GAAG,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC;IACxE,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,cAAc,CAAC,GAAG,cAAc,CAAC;IAExF,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC1C,CAAC,CAAC;AAfW,QAAA,iBAAiB,qBAe5B;AAGK,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAU,EAAE;IAC3D,OAAO,IAAA,yBAAiB,EAAC,MAAM,EAAE,2BAAmB,CAAC,CAAC;AACvD,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B;AAEK,MAAM,sBAAsB,GAAG,CAAC,MAAc,EAAU,EAAE;IAChE,OAAO,IAAA,yBAAiB,EAAC,MAAM,EAAE,gCAAwB,CAAC,CAAC;AAC5D,CAAC,CAAC;AAFW,QAAA,sBAAsB,0BAEjC","sourcesContent":["// === Currency Rounding Constants ===\nexport const BaseCurrencyRoundTo = 0.01;\nexport const SecondaryCurrencyRoundTo = 1000;\n\n// === Safely rounds a number to the nearest rounding unit ===\nexport const roundCurrencySync = (amount: number, roundingFactor: number): number => {\n\tif (\n\t\ttypeof amount !== 'number' ||\n\t\tisNaN(amount) ||\n\t\ttypeof roundingFactor !== 'number' ||\n\t\troundingFactor <= 0 ||\n\t\tamount === 0\n\t) {\n\t\treturn 0;\n\t}\n\n\tconst decimals = (roundingFactor.toString().split('.')[1] || '').length;\n\tconst rounded = Math.round((amount + Number.EPSILON) / roundingFactor) * roundingFactor;\n\n\treturn Number(rounded.toFixed(decimals));\n};\n\n// === Specific rounding functions for base and secondary currencies ===\nexport const roundBaseCurrency = (amount: number): number => {\n\treturn roundCurrencySync(amount, BaseCurrencyRoundTo);\n};\n\nexport const roundSecondaryCurrency = (amount: number): number => {\n\treturn roundCurrencySync(amount, SecondaryCurrencyRoundTo);\n};\n"]}
|
|
@@ -12,7 +12,7 @@ const roundCurrencySync = (amount, roundingFactor) => {
|
|
|
12
12
|
return 0;
|
|
13
13
|
}
|
|
14
14
|
const decimals = (roundingFactor.toString().split('.')[1] || '').length;
|
|
15
|
-
const rounded = Math.round(amount / roundingFactor) * roundingFactor;
|
|
15
|
+
const rounded = Math.round((amount + Number.EPSILON) / roundingFactor) * roundingFactor;
|
|
16
16
|
return Number(rounded.toFixed(decimals));
|
|
17
17
|
};
|
|
18
18
|
exports.roundCurrencySync = roundCurrencySync;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currency.js","sourceRoot":"/","sources":["utilities/shared/currency.ts"],"names":[],"mappings":";;;AACa,QAAA,mBAAmB,GAAG,IAAI,CAAC;AAC3B,QAAA,wBAAwB,GAAG,IAAI,CAAC;AAGtC,MAAM,iBAAiB,GAAG,CAAC,MAAc,EAAE,cAAsB,EAAU,EAAE;IACnF,IACC,OAAO,MAAM,KAAK,QAAQ;QAC1B,KAAK,CAAC,MAAM,CAAC;QACb,OAAO,cAAc,KAAK,QAA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AAC,CAAC;AACvD,CAAC,CAAC;AAFW,QAAA,iBAAiB,qBAE5B;AAEK,MAAM,sBAAsB,GAAG,CAAC,MAAc,EAAU,EAAE;IAChE,OAAO,IAAA,yBAAiB,EAAC,MAAM,EAAE,gCAAwB,CAAC,CAAC;AAC5D,CAAC,CAAC;AAFW,QAAA,sBAAsB,0BAEjC","sourcesContent":["// === Currency Rounding Constants ===\nexport const BaseCurrencyRoundTo = 0.01;\nexport const SecondaryCurrencyRoundTo = 1000;\n\n// === Safely rounds a number to the nearest rounding unit ===\nexport const roundCurrencySync = (amount: number, roundingFactor: number): number => {\n\tif (\n\t\ttypeof amount !== 'number' ||\n\t\tisNaN(amount) ||\n\t\ttypeof roundingFactor !== 'number' ||\n\t\troundingFactor <= 0 ||\n\t\tamount === 0\n\t) {\n\t\treturn 0;\n\t}\n\n\tconst decimals = (roundingFactor.toString().split('.')[1] || '').length;\n\tconst rounded = Math.round((amount + Number.EPSILON) / roundingFactor) * roundingFactor;\n\n\treturn Number(rounded.toFixed(decimals));\n};\n\n// === Specific rounding functions for base and secondary currencies ===\nexport const roundBaseCurrency = (amount: number): number => {\n\treturn roundCurrencySync(amount, BaseCurrencyRoundTo);\n};\n\nexport const roundSecondaryCurrency = (amount: number): number => {\n\treturn roundCurrencySync(amount, SecondaryCurrencyRoundTo);\n};\n"]}
|