@lyxa.ai/core 1.2.25 → 1.2.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 (30) hide show
  1. package/dist/libraries/map/providers/google-maps.js +0 -4
  2. package/dist/libraries/map/providers/google-maps.js.map +1 -1
  3. package/dist/libraries/mongo/models/embedded/adjustment-information.model.d.ts +1 -6
  4. package/dist/libraries/mongo/models/embedded/adjustment-information.model.js +4 -18
  5. package/dist/libraries/mongo/models/embedded/adjustment-information.model.js.map +1 -1
  6. package/dist/libraries/mongo/models/embedded/order-extra-time.settings.d.ts +13 -0
  7. package/dist/libraries/mongo/models/embedded/order-extra-time.settings.js +48 -0
  8. package/dist/libraries/mongo/models/embedded/order-extra-time.settings.js.map +1 -0
  9. package/dist/libraries/mongo/models/setting.model.d.ts +2 -0
  10. package/dist/libraries/mongo/models/setting.model.js +6 -0
  11. package/dist/libraries/mongo/models/setting.model.js.map +1 -1
  12. package/dist/libraries/osrm/index.d.ts +2 -11
  13. package/dist/libraries/osrm/index.js +5 -93
  14. package/dist/libraries/osrm/index.js.map +1 -1
  15. package/dist/libraries/osrm/osrm-client.d.ts +16 -0
  16. package/dist/libraries/osrm/osrm-client.js +81 -0
  17. package/dist/libraries/osrm/osrm-client.js.map +1 -0
  18. package/dist/libraries/osrm/osrm-service.d.ts +8 -0
  19. package/dist/libraries/osrm/osrm-service.js +61 -0
  20. package/dist/libraries/osrm/osrm-service.js.map +1 -0
  21. package/dist/libraries/osrm/types.js.map +1 -1
  22. package/dist/types/README.md +1 -1
  23. package/dist/types/package.json +1 -1
  24. package/dist/types/utilities/shared/index.d.ts +1 -0
  25. package/dist/types/utilities/shared/index.js +1 -0
  26. package/dist/types/utilities/shared/index.js.map +1 -1
  27. package/dist/utilities/shared/index.d.ts +1 -0
  28. package/dist/utilities/shared/index.js +1 -0
  29. package/dist/utilities/shared/index.js.map +1 -1
  30. package/package.json +1 -1
@@ -347,7 +347,6 @@ let GoogleMapsService = class GoogleMapsService {
347
347
  languageCode: 'en-US',
348
348
  units: 'METRIC',
349
349
  };
350
- console.log('Request body for getDistanceInfo V2:', body);
351
350
  const fieldMask = 'routes.duration,routes.distanceMeters';
352
351
  const response = await axios_1.default.post(this._routeURL, body, {
353
352
  headers: {
@@ -356,7 +355,6 @@ let GoogleMapsService = class GoogleMapsService {
356
355
  'X-Goog-FieldMask': fieldMask,
357
356
  },
358
357
  });
359
- console.log('Response from getDistanceInfo V2:', response.data);
360
358
  const route = response.data.routes[0];
361
359
  const distance = this.toDistanceDTO(route.distanceMeters);
362
360
  const duration = this.toDurationDTO(route.duration);
@@ -387,7 +385,6 @@ let GoogleMapsService = class GoogleMapsService {
387
385
  languageCode: 'en-US',
388
386
  units: 'METRIC',
389
387
  };
390
- console.log('Request body for getDistanceInfo V2:', body);
391
388
  const fieldMask = 'routes';
392
389
  const response = await axios_1.default.post(this._routeURL, body, {
393
390
  headers: {
@@ -396,7 +393,6 @@ let GoogleMapsService = class GoogleMapsService {
396
393
  'X-Goog-FieldMask': fieldMask,
397
394
  },
398
395
  });
399
- console.log('Response from getWaypointDistanceInfo V2:', JSON.stringify(response.data));
400
396
  const route = response.data.routes[0];
401
397
  const distance = this.toDistanceDTO(route.distanceMeters);
402
398
  const duration = this.toDurationDTO(route.duration);
@@ -1 +1 @@
1
- {"version":3,"file":"google-maps.js","sourceRoot":"/","sources":["libraries/map/providers/google-maps.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAW1B,2DAA6C;AAC7C,yCAAyC;AACzC,uCAA2C;AAC3C,mCAAiD;AACjD,mCAAgC;AAChC,+CAA0D;AAU1D,IAAa,iBAAiB,GAA9B,MAAa,iBAAiB;IAOQ;IAN7B,OAAO,CAAqB;IAC5B,QAAQ,CAA8B;IACtC,SAAS,GAAW,2DAA2D,CAAC;IAChF,eAAe,GAAW,oEAAoE,CAAC;IAEvG,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AK,CAAC;4BACd,CAAC,CAAC,GAAG,KAAK,QAAQ;4BAClB,CAAC,CAAC,OAAO,KAAK,CAAC;gCACd,CAAC,CAAC,GAAG,KAAK,cAAc;gCACxB,CAAC,CAAC,GAAG,KAAK,UAAU,OAAO,OAAO;YACvC,CAAC,CAAC,OAAO,CAAC;QAEX,OAAO,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;IACvD,CAAC;IAOO,aAAa,CAAC,cAAsB;QAC3C,MAAM,aAAa,GAAG,cAAc,CAAC;QACrC,MAAM,YAAY,GAAG,GAAG,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC;QAEhE,OAAO,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;IACrD,CAAC;CACD,CAAA;AA9jBY,8CAAiB;4BAAjB,iBAAiB;IAO3B,WAAA,IAAA,eAAM,EAAC,GAAG,EAAE,CAAC,oBAAY,CAAC,CAAA;qCAAuB,oBAAY;GAPnD,iBAAiB,CA8jB7B","sourcesContent":["import axios from 'axios';\nimport {\n\tIMapService,\n\tICoordinate,\n\tIDistance,\n\tIDuration,\n\tILeg,\n\tIDistanceInfo,\n\tIWaypointDistanceInfo,\n\tIRouteMatrixDTO,\n} from '../interfaces/IMapService';\nimport * as polyline from '@mapbox/polyline';\nimport { TRPCError } from '@trpc/server';\nimport { RedisService } from '../../redis';\nimport { createHash, randomBytes } from 'crypto';\nimport { Inject } from 'typedi';\nimport { GoogleMapsUsageModel } from '../../mongo/models';\n\ninterface RouteMatrixItem {\n\toriginIndex: number;\n\tdestinationIndex: number;\n\tdistanceMeters?: number;\n\tduration?: string;\n\tcondition: string;\n}\n\nexport class GoogleMapsService implements IMapService {\n\tprivate _apiKey: string | undefined;\n\tprivate logModel: typeof GoogleMapsUsageModel;\n\tprivate _routeURL: string = 'https://routes.googleapis.com/directions/v2:computeRoutes';\n\tprivate _routeMatrixURL: string = 'https://routes.googleapis.com/distanceMatrix/v2:computeRouteMatrix';\n\n\tconstructor(\n\t\t@Inject(() => RedisService) private redisService: RedisService,\n\t\tapiKey: string\n\t) {\n\t\tthis._apiKey = apiKey;\n\t\tthis.logModel = GoogleMapsUsageModel as typeof GoogleMapsUsageModel;\n\t}\n\n\tprivate createCacheKey(origin: ICoordinate, destination: ICoordinate, waypoints: ICoordinate[] = []) {\n\t\tconst originKey = `${origin.latitude},${origin.longitude}`;\n\t\tconst destinationKey = `${destination.latitude},${destination.longitude}`;\n\n\t\tlet keyData = { origin: originKey, destination: destinationKey, waypoints: [] as string[] };\n\n\t\tif (waypoints && waypoints.length > 0) {\n\t\t\tkeyData.waypoints = waypoints.map(point => `${point.latitude},${point.longitude}`).sort();\n\t\t}\n\n\t\treturn createHash('md5').update(JSON.stringify(keyData)).digest('hex');\n\t}\n\n\tprivate async acquireDistributedLock(key: string, ttl = 10) {\n\t\tconst token = randomBytes(16).toString('hex');\n\t\tconst lockKey = `lock:${key}`;\n\n\t\tconst result = await this.redisService.redisClient.set(lockKey, token, 'EX', ttl, 'NX');\n\t\treturn result ? { token, lockKey } : null;\n\t}\n\n\tprivate async releaseDistributedLock(lockKey: string, token: string) {\n\t\tconst lua = `\n if redis.call(\"get\", KEYS[1]) == ARGV[1] then\n return redis.call(\"del\", KEYS[1])\n else\n return 0\n end\n `;\n\t\treturn this.redisService.redisClient.eval(lua, 1, lockKey, token);\n\t}\n\n\tprivate async logApiUsage(\n\t\tendpoint: string,\n\t\tcacheHit = false,\n\t\tmetadata: {\n\t\t\torigin?: ICoordinate;\n\t\t\tdestination?: ICoordinate;\n\t\t\twaypoints?: ICoordinate[];\n\t\t\tipAddress?: string;\n\t\t\tuserAgent?: string;\n\t\t} = {},\n\t\tresponseTime: number,\n\t\terror?: Error\n\t) {\n\t\ttry {\n\t\t\tawait this.logModel.create({\n\t\t\t\tendpoint,\n\t\t\t\tcacheHit,\n\t\t\t\terror: error ? error.message : null,\n\t\t\t\tresponseTime: responseTime,\n\t\t\t\tmetadata: {\n\t\t\t\t\torigin: metadata.origin || null,\n\t\t\t\t\tdestination: metadata.destination || null,\n\t\t\t\t\twaypoints: metadata.waypoints || null,\n\t\t\t\t\tipAddress: metadata.ipAddress || null,\n\t\t\t\t\tuserAgent: metadata.userAgent || null,\n\t\t\t\t},\n\t\t\t});\n\t\t} catch (logError) {\n\t\t\tconsole.error('Failed to log API usage:', logError);\n\t\t}\n\t}\n\n\tprivate clearRouteCache = async (origin: ICoordinate, destination: ICoordinate, waypoints = []) => {\n\t\tconst cacheKey = waypoints\n\t\t\t? `distance_waypoints:${this.createCacheKey(origin, destination, waypoints)}`\n\t\t\t: `distance:${this.createCacheKey(origin, destination)}`;\n\n\t\treturn await this.redisService.deleteCachedObject(cacheKey);\n\t};\n\n\tprivate getCacheStats = async () => {\n\t\tconst keys = await this.redisService.redisClient.keys('distance*');\n\t\treturn {\n\t\t\ttotalCachedRoutes: keys.length,\n\t\t\tcacheKeys: keys,\n\t\t};\n\t};\n\n\tpublic async getDistanceInfo(origin: ICoordinate, destination: ICoordinate): Promise<IDistanceInfo> {\n\t\tconst startTime = Date.now();\n\t\tconst cacheKey = `distance:${this.createCacheKey(origin, destination)}`;\n\t\tconst cacheTTL = 3600;\n\n\t\ttry {\n\t\t\tconst cachedData: IDistanceInfo | undefined = await this.redisService.getCachedObject(cacheKey);\n\t\t\tif (cachedData) {\n\t\t\t\tconst responseTime = Date.now() - startTime;\n\t\t\t\tawait this.logApiUsage(\n\t\t\t\t\t'DistanceInfoGoogle',\n\t\t\t\t\ttrue,\n\t\t\t\t\t{\n\t\t\t\t\t\torigin,\n\t\t\t\t\t\tdestination,\n\t\t\t\t\t},\n\t\t\t\t\tresponseTime\n\t\t\t\t);\n\t\t\t\treturn cachedData;\n\t\t\t}\n\n\t\t\tconst lock = await this.acquireDistributedLock(cacheKey);\n\n\t\t\ttry {\n\t\t\t\tconst cachedDataAfterLock: IDistanceInfo | undefined =\n\t\t\t\t\tawait this.redisService.getCachedObject(cacheKey);\n\t\t\t\tif (cachedDataAfterLock) {\n\t\t\t\t\tconst responseTime = Date.now() - startTime;\n\t\t\t\t\tawait this.logApiUsage(\n\t\t\t\t\t\t'DistanceInfoGoogle',\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\torigin,\n\t\t\t\t\t\t\tdestination,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tresponseTime\n\t\t\t\t\t);\n\t\t\t\t\treturn cachedDataAfterLock;\n\t\t\t\t}\n\n\t\t\t\tconst result = await this.getDistanceInfoFromGoogle(origin, destination);\n\n\t\t\t\tawait this.redisService.cacheObject(cacheKey, result, cacheTTL);\n\n\t\t\t\tconst responseTime = Date.now() - startTime;\n\t\t\t\tawait this.logApiUsage(\n\t\t\t\t\t'DistanceInfoGoogle',\n\t\t\t\t\tfalse,\n\t\t\t\t\t{\n\t\t\t\t\t\torigin,\n\t\t\t\t\t\tdestination,\n\t\t\t\t\t},\n\t\t\t\t\tresponseTime\n\t\t\t\t);\n\n\t\t\t\treturn result;\n\t\t\t} finally {\n\t\t\t\tif (lock) {\n\t\t\t\t\tawait this.releaseDistributedLock(lock.lockKey, lock.token);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error: any) {\n\t\t\tconst responseTime = Date.now() - startTime;\n\t\t\tawait this.logApiUsage(\n\t\t\t\t'DistanceInfoGoogle',\n\t\t\t\tfalse,\n\t\t\t\t{\n\t\t\t\t\torigin,\n\t\t\t\t\tdestination,\n\t\t\t\t},\n\t\t\t\tresponseTime,\n\t\t\t\terror\n\t\t\t);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to fetch distance information from Maps API.',\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async getDistanceInfoFromGoogle_DEPRECATED(\n\t\torigin: ICoordinate,\n\t\tdestination: ICoordinate\n\t): Promise<IDistanceInfo> {\n\t\ttry {\n\t\t\tconst url = `https://maps.googleapis.com/maps/api/directions/json?origin=${origin.latitude}, ${origin.longitude}&destination=${destination.latitude}, ${destination.longitude}&key=${this._apiKey}&mode=DRIVING`;\n\n\t\t\tconst { data } = await axios.get(url);\n\n\t\t\tconst legs = data?.routes[0]?.legs[0];\n\n\t\t\tconst distance = legs?.distance;\n\t\t\tconst duration = legs?.duration;\n\n\t\t\tif (!distance || !duration) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\t\tmessage: 'No path exists from origin to destination.',\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn { distance, duration };\n\t\t} catch (error) {\n\t\t\tconsole.error(`Error in getDistanceInfo: ${error}`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to fetch distance information from Google Maps API.',\n\t\t\t});\n\t\t}\n\t}\n\n\tpublic async getWaypointsDistanceInfo(\n\t\torigin: ICoordinate,\n\t\tdestination: ICoordinate,\n\t\twaypoints: Array<ICoordinate>\n\t): Promise<IWaypointDistanceInfo> {\n\t\tconst startTime = Date.now();\n\t\tconst cacheKey = `distance_waypoints:${this.createCacheKey(origin, destination, waypoints)}`;\n\t\tconst cacheTTL = 3600;\n\n\t\ttry {\n\t\t\tconst cachedData: IWaypointDistanceInfo | undefined = await this.redisService.getCachedObject(cacheKey);\n\t\t\tif (cachedData) {\n\t\t\t\tconst responseTime = Date.now() - startTime;\n\t\t\t\tawait this.logApiUsage(\n\t\t\t\t\t'DistanceInfoGoogleWithWayPoints',\n\t\t\t\t\ttrue,\n\t\t\t\t\t{\n\t\t\t\t\t\torigin,\n\t\t\t\t\t\tdestination,\n\t\t\t\t\t\twaypoints,\n\t\t\t\t\t},\n\t\t\t\t\tresponseTime\n\t\t\t\t);\n\t\t\t\treturn cachedData;\n\t\t\t}\n\n\t\t\tconst lock = await this.acquireDistributedLock(cacheKey);\n\n\t\t\ttry {\n\t\t\t\tconst cachedDataAfterLock: IWaypointDistanceInfo | undefined =\n\t\t\t\t\tawait this.redisService.getCachedObject(cacheKey);\n\t\t\t\tif (cachedDataAfterLock) {\n\t\t\t\t\tconst responseTime = Date.now() - startTime;\n\t\t\t\t\tawait this.logApiUsage(\n\t\t\t\t\t\t'DistanceInfoGoogleWithWayPoints',\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\torigin,\n\t\t\t\t\t\t\tdestination,\n\t\t\t\t\t\t\twaypoints,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tresponseTime\n\t\t\t\t\t);\n\t\t\t\t\treturn cachedDataAfterLock;\n\t\t\t\t}\n\n\t\t\t\tconst result = await this.getWaypointsDistanceInfoFromGoogle(origin, destination, waypoints);\n\n\t\t\t\tawait this.redisService.cacheObject(cacheKey, result, cacheTTL);\n\n\t\t\t\tconst responseTime = Date.now() - startTime;\n\t\t\t\tawait this.logApiUsage(\n\t\t\t\t\t'DistanceInfoGoogleWithWayPoints',\n\t\t\t\t\tfalse,\n\t\t\t\t\t{\n\t\t\t\t\t\torigin,\n\t\t\t\t\t\tdestination,\n\t\t\t\t\t\twaypoints,\n\t\t\t\t\t},\n\t\t\t\t\tresponseTime\n\t\t\t\t);\n\n\t\t\t\treturn result;\n\t\t\t} finally {\n\t\t\t\tif (lock) {\n\t\t\t\t\tawait this.releaseDistributedLock(lock.lockKey, lock.token);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error: any) {\n\t\t\tconst responseTime = Date.now() - startTime;\n\t\t\tawait this.logApiUsage(\n\t\t\t\t'DistanceInfoGoogleWithWayPoints',\n\t\t\t\tfalse,\n\t\t\t\t{\n\t\t\t\t\torigin,\n\t\t\t\t\tdestination,\n\t\t\t\t\twaypoints,\n\t\t\t\t},\n\t\t\t\tresponseTime,\n\t\t\t\terror\n\t\t\t);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to fetch waypoint distance information from Maps API.',\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async getWaypointsDistanceInfoFromGoogle_DEPRECATED(\n\t\torigin: ICoordinate,\n\t\tdestination: ICoordinate,\n\t\twaypoints: Array<ICoordinate>\n\t): Promise<IWaypointDistanceInfo> {\n\t\ttry {\n\t\t\tconst waypointsStr = waypoints.map(point => `${point.latitude},${point.longitude}`).join('|');\n\n\t\t\tconst url = `https://maps.googleapis.com/maps/api/directions/json?origin=${origin.latitude},${origin.longitude}&destination=${destination.latitude},${destination.longitude}&waypoints=${waypointsStr}&key=${this._apiKey}&mode=DRIVING`;\n\n\t\t\tconst { data } = await axios.get(url);\n\n\t\t\tconst routes = data?.routes[0];\n\n\t\t\tconst overviewPolyline = polyline.decode(routes?.overview_polyline?.points);\n\n\t\t\tconst legs = (routes?.legs ?? []).map((leg: { steps: any[]; distance: any; duration: any }) => {\n\t\t\t\tconst overviewPolyline = leg?.steps?.flatMap(step => polyline.decode(step?.polyline?.points));\n\n\t\t\t\treturn {\n\t\t\t\t\tdistance: leg.distance,\n\t\t\t\t\tduration: leg.duration,\n\t\t\t\t\toverviewPolyline,\n\t\t\t\t};\n\t\t\t});\n\n\t\t\tconst totalDistance = legs?.reduce(\n\t\t\t\t(acc: any, curr: { distance: { value: any } }) => acc + curr.distance.value,\n\t\t\t\t0\n\t\t\t);\n\t\t\tconst distance = {\n\t\t\t\ttext: `${(totalDistance / 1000).toFixed(2)} km`,\n\t\t\t\tvalue: totalDistance,\n\t\t\t};\n\n\t\t\tconst totalDuration = legs?.reduce(\n\t\t\t\t(acc: any, curr: { duration: { value: any } }) => acc + curr.duration.value,\n\t\t\t\t0\n\t\t\t);\n\t\t\tconst duration = {\n\t\t\t\ttext: `${Math.round(totalDuration / 60)} mins`,\n\t\t\t\tvalue: totalDuration,\n\t\t\t};\n\n\t\t\tif (!distance || !duration) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\t\tmessage: 'No path exists from origin to destination.',\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn { distance, duration, legs, overviewPolyline };\n\t\t} catch (error) {\n\t\t\tconsole.error(`Error in getWaypointsDistanceInfo: ${error}`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to fetch waypoint distance information from Google Maps API.',\n\t\t\t});\n\t\t}\n\t}\n\n\tpublic async getDistanceMatrix(\n\t\torigins: Array<ICoordinate>,\n\t\tdestinations: Array<ICoordinate>\n\t): Promise<IRouteMatrixDTO[]> {\n\t\ttry {\n\t\t\tconst body = {\n\t\t\t\torigins: origins.map(this.toWaypoint),\n\t\t\t\tdestinations: destinations.map(this.toWaypoint),\n\t\t\t\ttravelMode: 'DRIVE',\n\t\t\t\troutingPreference: 'TRAFFIC_AWARE',\n\t\t\t};\n\n\t\t\tconst fieldMask = 'originIndex,destinationIndex,duration,distanceMeters,condition';\n\n\t\t\tconst response = await axios.post(this._routeMatrixURL, body, {\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t'X-Goog-Api-Key': this._apiKey,\n\t\t\t\t\t'X-Goog-FieldMask': fieldMask,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\t// The API returns an array of route elements\n\t\t\tconst results: IRouteMatrixDTO[] = response.data.map((item: RouteMatrixItem) => {\n\t\t\t\tconst distance = this.toDistanceDTO(item.distanceMeters ?? 0);\n\t\t\t\tconst duration = this.toDurationDTO(item.duration ?? '0s');\n\n\t\t\t\treturn {\n\t\t\t\t\tdistance,\n\t\t\t\t\tduration,\n\t\t\t\t\tcondition: item.condition,\n\t\t\t\t\toriginIndex: item.originIndex,\n\t\t\t\t\tdestinationIndex: item.destinationIndex,\n\t\t\t\t};\n\t\t\t});\n\n\t\t\treturn results;\n\t\t} catch (error) {\n\t\t\tconsole.error(`Error in getDistanceMatrix: ${error}`);\n\t\t}\n\n\t\treturn [];\n\t}\n\n\tprivate async getDistanceInfoFromGoogle(origin: ICoordinate, destination: ICoordinate): Promise<IDistanceInfo> {\n\t\ttry {\n\t\t\tconst body = {\n\t\t\t\torigin: this.toLocation(origin),\n\t\t\t\tdestination: this.toLocation(destination),\n\t\t\t\ttravelMode: 'DRIVE',\n\t\t\t\troutingPreference: 'TRAFFIC_AWARE',\n\t\t\t\tcomputeAlternativeRoutes: false,\n\t\t\t\trouteModifiers: {\n\t\t\t\t\tavoidTolls: false,\n\t\t\t\t\tavoidHighways: false,\n\t\t\t\t\tavoidFerries: false,\n\t\t\t\t},\n\t\t\t\tlanguageCode: 'en-US',\n\t\t\t\tunits: 'METRIC',\n\t\t\t};\n\n\t\t\tconsole.log('Request body for getDistanceInfo V2:', body);\n\n\t\t\tconst fieldMask = 'routes.duration,routes.distanceMeters';\n\n\t\t\tconst response = await axios.post(this._routeURL, body, {\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t'X-Goog-Api-Key': this._apiKey,\n\t\t\t\t\t'X-Goog-FieldMask': fieldMask,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconsole.log('Response from getDistanceInfo V2:', response.data);\n\n\t\t\tconst route = response.data.routes[0];\n\n\t\t\tconst distance = this.toDistanceDTO(route.distanceMeters);\n\t\t\tconst duration = this.toDurationDTO(route.duration);\n\n\t\t\treturn { distance, duration };\n\t\t} catch (error) {\n\t\t\tconsole.error(`Error in getDistanceInfo V2: ${error}`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to fetch distance information from Google Maps API.',\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async getWaypointsDistanceInfoFromGoogle(\n\t\torigin: ICoordinate,\n\t\tdestination: ICoordinate,\n\t\twaypoints: Array<ICoordinate>\n\t): Promise<IWaypointDistanceInfo> {\n\t\ttry {\n\t\t\tconst body = {\n\t\t\t\torigin: this.toLocation(origin),\n\t\t\t\tdestination: this.toLocation(destination),\n\t\t\t\tintermediates: waypoints.map(this.toLocation),\n\t\t\t\ttravelMode: 'DRIVE',\n\t\t\t\troutingPreference: 'TRAFFIC_AWARE',\n\t\t\t\tcomputeAlternativeRoutes: false,\n\t\t\t\trouteModifiers: {\n\t\t\t\t\tavoidTolls: false,\n\t\t\t\t\tavoidHighways: false,\n\t\t\t\t\tavoidFerries: false,\n\t\t\t\t},\n\t\t\t\tlanguageCode: 'en-US',\n\t\t\t\tunits: 'METRIC',\n\t\t\t};\n\n\t\t\tconsole.log('Request body for getDistanceInfo V2:', body);\n\n\t\t\tconst fieldMask = 'routes';\n\n\t\t\tconst response = await axios.post(this._routeURL, body, {\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t'X-Goog-Api-Key': this._apiKey,\n\t\t\t\t\t'X-Goog-FieldMask': fieldMask,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconsole.log('Response from getWaypointDistanceInfo V2:', JSON.stringify(response.data));\n\n\t\t\tconst route = response.data.routes[0];\n\n\t\t\tconst distance = this.toDistanceDTO(route.distanceMeters);\n\t\t\tconst duration = this.toDurationDTO(route.duration);\n\t\t\tconst overviewPolyline = polyline.decode(route.polyline.encodedPolyline);\n\n\t\t\tconst legs = (route?.legs ?? []).map(\n\t\t\t\t(leg: { polyline: { encodedPolyline: string }; distanceMeters: number; duration: string }) => {\n\t\t\t\t\tconst overviewPolyline = polyline.decode(leg.polyline.encodedPolyline);\n\n\t\t\t\t\tconst legDistance = this.toDistanceDTO(leg.distanceMeters);\n\t\t\t\t\tconst legDuration = this.toDurationDTO(leg.duration);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdistance: legDistance,\n\t\t\t\t\t\tduration: legDuration,\n\t\t\t\t\t\toverviewPolyline,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t);\n\n\t\t\treturn { distance, duration, overviewPolyline, legs };\n\t\t} catch (error) {\n\t\t\tconsole.error(`Error in getWaypointDistanceInfo V2: ${error}`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to fetch waypoint distance information from Google Maps API.',\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Converts an ICoordinate to a location object for Google Maps API\n\t * @param coord - ICoordinate object\n\t * @returns Location object for Google Maps API\n\t */\n\tprivate toLocation(coord: ICoordinate) {\n\t\treturn { location: { latLng: { latitude: coord.latitude, longitude: coord.longitude } } };\n\t}\n\n\t/**\n\t * Converts an ICoordinate to a waypoint object for Google Maps API\n\t * @param coord - ICoordinate object\n\t * @returns Waypoint object for Google Maps API\n\t */\n\tprivate toWaypoint(coord: ICoordinate) {\n\t\treturn { waypoint: { location: { latLng: { latitude: coord.latitude, longitude: coord.longitude } } } };\n\t}\n\n\t/**\n\t * Converts a duration string from Google Maps API to an IDuration object\n\t * @param duration in format \"Xs\" where X is number of seconds\n\t * @returns IDuration object\n\t */\n\tprivate toDurationDTO(duration: string): IDuration {\n\t\tconst durationSeconds = parseInt(duration.replace('s', ''));\n\n\t\tconst hours = Math.floor(durationSeconds / 3600);\n\t\tconst minutes = Math.ceil((durationSeconds % 3600) / 60);\n\n\t\tconst durationText = durationSeconds\n\t\t\t? durationSeconds < 60\n\t\t\t\t? `1 min`\n\t\t\t\t: durationSeconds < 3600\n\t\t\t\t\t? minutes === 1\n\t\t\t\t\t\t? '1 min'\n\t\t\t\t\t\t: `${minutes} mins`\n\t\t\t\t\t: hours === 1\n\t\t\t\t\t\t? minutes === 0\n\t\t\t\t\t\t\t? '1 hour'\n\t\t\t\t\t\t\t: minutes === 1\n\t\t\t\t\t\t\t\t? '1 hour 1 min'\n\t\t\t\t\t\t\t\t: `1 hour ${minutes} mins`\n\t\t\t\t\t\t: minutes === 0\n\t\t\t\t\t\t\t? `${hours} hours`\n\t\t\t\t\t\t\t: minutes === 1\n\t\t\t\t\t\t\t\t? `${hours} hours 1 min`\n\t\t\t\t\t\t\t\t: `${hours} hours ${minutes} mins`\n\t\t\t: '1 min';\n\n\t\treturn { value: durationSeconds, text: durationText };\n\t}\n\n\t/**\n\t * Converts a distance in meters from Google Maps API to an IDistance object\n\t * @param distanceMeters distance in meters\n\t * @returns IDistance object\n\t */\n\tprivate toDistanceDTO(distanceMeters: number): IDistance {\n\t\tconst distanceValue = distanceMeters;\n\t\tconst distanceText = `${(distanceMeters / 1000).toFixed(1)} km`;\n\n\t\treturn { value: distanceValue, text: distanceText };\n\t}\n}\n"]}
1
+ {"version":3,"file":"google-maps.js","sourceRoot":"/","sources":["libraries/map/providers/google-maps.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA0B;AAW1B,2DAA6C;AAC7C,yCAAyC;AACzC,uCAA2C;AAC3C,mCAAiD;AACjD,mCAAgC;AAChC,+CAA0D;AAU1D,IAAa,iBAAiB,GAA9B,MAAa,iBAAiB;IAOQ;IAN7B,OAAO,CAAqB;IAC5B,QAAQ,CAA8B;IACtC,SAAS,GAAW,2DAA2D,CAAC;IAChF,eAAe,GAAW,oEAAoE,CAAC;IAEvG,YACqC,YAA0B,EAC9D,MAAc;QADsB,iBAAY,GAAZ,YAAY,CAAc;QAG9D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,QAAQ,GAAG,6BAAmD,CAAC;IACrE,CAAC;IAEO,cAAc,CAAC,MAAmB,EAAE,WAAwB,EAAE,YAA2B,EAAE;QAClG,MAAM,SAAS,GAAG,GAAG,MAAM,CAAC,QAAQ,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC;QAC3D,MAAM,cAAc,GAAG,GAAG,WAAW,CAAC,QAAQ,IAAI,WAAW,CAAC,SAAS,EAAE,CAAC;QAE1E,IAAI,OAAO,GAAG,EAAE,MAAM,EAAE,SAAS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\n\tIDuration,\n\tILeg,\n\tIDistanceInfo,\n\tIWaypointDistanceInfo,\n\tIRouteMatrixDTO,\n} from '../interfaces/IMapService';\nimport * as polyline from '@mapbox/polyline';\nimport { TRPCError } from '@trpc/server';\nimport { RedisService } from '../../redis';\nimport { createHash, randomBytes } from 'crypto';\nimport { Inject } from 'typedi';\nimport { GoogleMapsUsageModel } from '../../mongo/models';\n\ninterface RouteMatrixItem {\n\toriginIndex: number;\n\tdestinationIndex: number;\n\tdistanceMeters?: number;\n\tduration?: string;\n\tcondition: string;\n}\n\nexport class GoogleMapsService implements IMapService {\n\tprivate _apiKey: string | undefined;\n\tprivate logModel: typeof GoogleMapsUsageModel;\n\tprivate _routeURL: string = 'https://routes.googleapis.com/directions/v2:computeRoutes';\n\tprivate _routeMatrixURL: string = 'https://routes.googleapis.com/distanceMatrix/v2:computeRouteMatrix';\n\n\tconstructor(\n\t\t@Inject(() => RedisService) private redisService: RedisService,\n\t\tapiKey: string\n\t) {\n\t\tthis._apiKey = apiKey;\n\t\tthis.logModel = GoogleMapsUsageModel as typeof GoogleMapsUsageModel;\n\t}\n\n\tprivate createCacheKey(origin: ICoordinate, destination: ICoordinate, waypoints: ICoordinate[] = []) {\n\t\tconst originKey = `${origin.latitude},${origin.longitude}`;\n\t\tconst destinationKey = `${destination.latitude},${destination.longitude}`;\n\n\t\tlet keyData = { origin: originKey, destination: destinationKey, waypoints: [] as string[] };\n\n\t\tif (waypoints && waypoints.length > 0) {\n\t\t\tkeyData.waypoints = waypoints.map(point => `${point.latitude},${point.longitude}`).sort();\n\t\t}\n\n\t\treturn createHash('md5').update(JSON.stringify(keyData)).digest('hex');\n\t}\n\n\tprivate async acquireDistributedLock(key: string, ttl = 10) {\n\t\tconst token = randomBytes(16).toString('hex');\n\t\tconst lockKey = `lock:${key}`;\n\n\t\tconst result = await this.redisService.redisClient.set(lockKey, token, 'EX', ttl, 'NX');\n\t\treturn result ? { token, lockKey } : null;\n\t}\n\n\tprivate async releaseDistributedLock(lockKey: string, token: string) {\n\t\tconst lua = `\n if redis.call(\"get\", KEYS[1]) == ARGV[1] then\n return redis.call(\"del\", KEYS[1])\n else\n return 0\n end\n `;\n\t\treturn this.redisService.redisClient.eval(lua, 1, lockKey, token);\n\t}\n\n\tprivate async logApiUsage(\n\t\tendpoint: string,\n\t\tcacheHit = false,\n\t\tmetadata: {\n\t\t\torigin?: ICoordinate;\n\t\t\tdestination?: ICoordinate;\n\t\t\twaypoints?: ICoordinate[];\n\t\t\tipAddress?: string;\n\t\t\tuserAgent?: string;\n\t\t} = {},\n\t\tresponseTime: number,\n\t\terror?: Error\n\t) {\n\t\ttry {\n\t\t\tawait this.logModel.create({\n\t\t\t\tendpoint,\n\t\t\t\tcacheHit,\n\t\t\t\terror: error ? error.message : null,\n\t\t\t\tresponseTime: responseTime,\n\t\t\t\tmetadata: {\n\t\t\t\t\torigin: metadata.origin || null,\n\t\t\t\t\tdestination: metadata.destination || null,\n\t\t\t\t\twaypoints: metadata.waypoints || null,\n\t\t\t\t\tipAddress: metadata.ipAddress || null,\n\t\t\t\t\tuserAgent: metadata.userAgent || null,\n\t\t\t\t},\n\t\t\t});\n\t\t} catch (logError) {\n\t\t\tconsole.error('Failed to log API usage:', logError);\n\t\t}\n\t}\n\n\tprivate clearRouteCache = async (origin: ICoordinate, destination: ICoordinate, waypoints = []) => {\n\t\tconst cacheKey = waypoints\n\t\t\t? `distance_waypoints:${this.createCacheKey(origin, destination, waypoints)}`\n\t\t\t: `distance:${this.createCacheKey(origin, destination)}`;\n\n\t\treturn await this.redisService.deleteCachedObject(cacheKey);\n\t};\n\n\tprivate getCacheStats = async () => {\n\t\tconst keys = await this.redisService.redisClient.keys('distance*');\n\t\treturn {\n\t\t\ttotalCachedRoutes: keys.length,\n\t\t\tcacheKeys: keys,\n\t\t};\n\t};\n\n\tpublic async getDistanceInfo(origin: ICoordinate, destination: ICoordinate): Promise<IDistanceInfo> {\n\t\tconst startTime = Date.now();\n\t\tconst cacheKey = `distance:${this.createCacheKey(origin, destination)}`;\n\t\tconst cacheTTL = 3600;\n\n\t\ttry {\n\t\t\tconst cachedData: IDistanceInfo | undefined = await this.redisService.getCachedObject(cacheKey);\n\t\t\tif (cachedData) {\n\t\t\t\tconst responseTime = Date.now() - startTime;\n\t\t\t\tawait this.logApiUsage(\n\t\t\t\t\t'DistanceInfoGoogle',\n\t\t\t\t\ttrue,\n\t\t\t\t\t{\n\t\t\t\t\t\torigin,\n\t\t\t\t\t\tdestination,\n\t\t\t\t\t},\n\t\t\t\t\tresponseTime\n\t\t\t\t);\n\t\t\t\treturn cachedData;\n\t\t\t}\n\n\t\t\tconst lock = await this.acquireDistributedLock(cacheKey);\n\n\t\t\ttry {\n\t\t\t\tconst cachedDataAfterLock: IDistanceInfo | undefined =\n\t\t\t\t\tawait this.redisService.getCachedObject(cacheKey);\n\t\t\t\tif (cachedDataAfterLock) {\n\t\t\t\t\tconst responseTime = Date.now() - startTime;\n\t\t\t\t\tawait this.logApiUsage(\n\t\t\t\t\t\t'DistanceInfoGoogle',\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\torigin,\n\t\t\t\t\t\t\tdestination,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tresponseTime\n\t\t\t\t\t);\n\t\t\t\t\treturn cachedDataAfterLock;\n\t\t\t\t}\n\n\t\t\t\tconst result = await this.getDistanceInfoFromGoogle(origin, destination);\n\n\t\t\t\tawait this.redisService.cacheObject(cacheKey, result, cacheTTL);\n\n\t\t\t\tconst responseTime = Date.now() - startTime;\n\t\t\t\tawait this.logApiUsage(\n\t\t\t\t\t'DistanceInfoGoogle',\n\t\t\t\t\tfalse,\n\t\t\t\t\t{\n\t\t\t\t\t\torigin,\n\t\t\t\t\t\tdestination,\n\t\t\t\t\t},\n\t\t\t\t\tresponseTime\n\t\t\t\t);\n\n\t\t\t\treturn result;\n\t\t\t} finally {\n\t\t\t\tif (lock) {\n\t\t\t\t\tawait this.releaseDistributedLock(lock.lockKey, lock.token);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error: any) {\n\t\t\tconst responseTime = Date.now() - startTime;\n\t\t\tawait this.logApiUsage(\n\t\t\t\t'DistanceInfoGoogle',\n\t\t\t\tfalse,\n\t\t\t\t{\n\t\t\t\t\torigin,\n\t\t\t\t\tdestination,\n\t\t\t\t},\n\t\t\t\tresponseTime,\n\t\t\t\terror\n\t\t\t);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to fetch distance information from Maps API.',\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async getDistanceInfoFromGoogle_DEPRECATED(\n\t\torigin: ICoordinate,\n\t\tdestination: ICoordinate\n\t): Promise<IDistanceInfo> {\n\t\ttry {\n\t\t\tconst url = `https://maps.googleapis.com/maps/api/directions/json?origin=${origin.latitude}, ${origin.longitude}&destination=${destination.latitude}, ${destination.longitude}&key=${this._apiKey}&mode=DRIVING`;\n\n\t\t\tconst { data } = await axios.get(url);\n\n\t\t\tconst legs = data?.routes[0]?.legs[0];\n\n\t\t\tconst distance = legs?.distance;\n\t\t\tconst duration = legs?.duration;\n\n\t\t\tif (!distance || !duration) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\t\tmessage: 'No path exists from origin to destination.',\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn { distance, duration };\n\t\t} catch (error) {\n\t\t\tconsole.error(`Error in getDistanceInfo: ${error}`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to fetch distance information from Google Maps API.',\n\t\t\t});\n\t\t}\n\t}\n\n\tpublic async getWaypointsDistanceInfo(\n\t\torigin: ICoordinate,\n\t\tdestination: ICoordinate,\n\t\twaypoints: Array<ICoordinate>\n\t): Promise<IWaypointDistanceInfo> {\n\t\tconst startTime = Date.now();\n\t\tconst cacheKey = `distance_waypoints:${this.createCacheKey(origin, destination, waypoints)}`;\n\t\tconst cacheTTL = 3600;\n\n\t\ttry {\n\t\t\tconst cachedData: IWaypointDistanceInfo | undefined = await this.redisService.getCachedObject(cacheKey);\n\t\t\tif (cachedData) {\n\t\t\t\tconst responseTime = Date.now() - startTime;\n\t\t\t\tawait this.logApiUsage(\n\t\t\t\t\t'DistanceInfoGoogleWithWayPoints',\n\t\t\t\t\ttrue,\n\t\t\t\t\t{\n\t\t\t\t\t\torigin,\n\t\t\t\t\t\tdestination,\n\t\t\t\t\t\twaypoints,\n\t\t\t\t\t},\n\t\t\t\t\tresponseTime\n\t\t\t\t);\n\t\t\t\treturn cachedData;\n\t\t\t}\n\n\t\t\tconst lock = await this.acquireDistributedLock(cacheKey);\n\n\t\t\ttry {\n\t\t\t\tconst cachedDataAfterLock: IWaypointDistanceInfo | undefined =\n\t\t\t\t\tawait this.redisService.getCachedObject(cacheKey);\n\t\t\t\tif (cachedDataAfterLock) {\n\t\t\t\t\tconst responseTime = Date.now() - startTime;\n\t\t\t\t\tawait this.logApiUsage(\n\t\t\t\t\t\t'DistanceInfoGoogleWithWayPoints',\n\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\torigin,\n\t\t\t\t\t\t\tdestination,\n\t\t\t\t\t\t\twaypoints,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tresponseTime\n\t\t\t\t\t);\n\t\t\t\t\treturn cachedDataAfterLock;\n\t\t\t\t}\n\n\t\t\t\tconst result = await this.getWaypointsDistanceInfoFromGoogle(origin, destination, waypoints);\n\n\t\t\t\tawait this.redisService.cacheObject(cacheKey, result, cacheTTL);\n\n\t\t\t\tconst responseTime = Date.now() - startTime;\n\t\t\t\tawait this.logApiUsage(\n\t\t\t\t\t'DistanceInfoGoogleWithWayPoints',\n\t\t\t\t\tfalse,\n\t\t\t\t\t{\n\t\t\t\t\t\torigin,\n\t\t\t\t\t\tdestination,\n\t\t\t\t\t\twaypoints,\n\t\t\t\t\t},\n\t\t\t\t\tresponseTime\n\t\t\t\t);\n\n\t\t\t\treturn result;\n\t\t\t} finally {\n\t\t\t\tif (lock) {\n\t\t\t\t\tawait this.releaseDistributedLock(lock.lockKey, lock.token);\n\t\t\t\t}\n\t\t\t}\n\t\t} catch (error: any) {\n\t\t\tconst responseTime = Date.now() - startTime;\n\t\t\tawait this.logApiUsage(\n\t\t\t\t'DistanceInfoGoogleWithWayPoints',\n\t\t\t\tfalse,\n\t\t\t\t{\n\t\t\t\t\torigin,\n\t\t\t\t\tdestination,\n\t\t\t\t\twaypoints,\n\t\t\t\t},\n\t\t\t\tresponseTime,\n\t\t\t\terror\n\t\t\t);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to fetch waypoint distance information from Maps API.',\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async getWaypointsDistanceInfoFromGoogle_DEPRECATED(\n\t\torigin: ICoordinate,\n\t\tdestination: ICoordinate,\n\t\twaypoints: Array<ICoordinate>\n\t): Promise<IWaypointDistanceInfo> {\n\t\ttry {\n\t\t\tconst waypointsStr = waypoints.map(point => `${point.latitude},${point.longitude}`).join('|');\n\n\t\t\tconst url = `https://maps.googleapis.com/maps/api/directions/json?origin=${origin.latitude},${origin.longitude}&destination=${destination.latitude},${destination.longitude}&waypoints=${waypointsStr}&key=${this._apiKey}&mode=DRIVING`;\n\n\t\t\tconst { data } = await axios.get(url);\n\n\t\t\tconst routes = data?.routes[0];\n\n\t\t\tconst overviewPolyline = polyline.decode(routes?.overview_polyline?.points);\n\n\t\t\tconst legs = (routes?.legs ?? []).map((leg: { steps: any[]; distance: any; duration: any }) => {\n\t\t\t\tconst overviewPolyline = leg?.steps?.flatMap(step => polyline.decode(step?.polyline?.points));\n\n\t\t\t\treturn {\n\t\t\t\t\tdistance: leg.distance,\n\t\t\t\t\tduration: leg.duration,\n\t\t\t\t\toverviewPolyline,\n\t\t\t\t};\n\t\t\t});\n\n\t\t\tconst totalDistance = legs?.reduce(\n\t\t\t\t(acc: any, curr: { distance: { value: any } }) => acc + curr.distance.value,\n\t\t\t\t0\n\t\t\t);\n\t\t\tconst distance = {\n\t\t\t\ttext: `${(totalDistance / 1000).toFixed(2)} km`,\n\t\t\t\tvalue: totalDistance,\n\t\t\t};\n\n\t\t\tconst totalDuration = legs?.reduce(\n\t\t\t\t(acc: any, curr: { duration: { value: any } }) => acc + curr.duration.value,\n\t\t\t\t0\n\t\t\t);\n\t\t\tconst duration = {\n\t\t\t\ttext: `${Math.round(totalDuration / 60)} mins`,\n\t\t\t\tvalue: totalDuration,\n\t\t\t};\n\n\t\t\tif (!distance || !duration) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\t\tmessage: 'No path exists from origin to destination.',\n\t\t\t\t});\n\t\t\t}\n\n\t\t\treturn { distance, duration, legs, overviewPolyline };\n\t\t} catch (error) {\n\t\t\tconsole.error(`Error in getWaypointsDistanceInfo: ${error}`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to fetch waypoint distance information from Google Maps API.',\n\t\t\t});\n\t\t}\n\t}\n\n\tpublic async getDistanceMatrix(\n\t\torigins: Array<ICoordinate>,\n\t\tdestinations: Array<ICoordinate>\n\t): Promise<IRouteMatrixDTO[]> {\n\t\ttry {\n\t\t\tconst body = {\n\t\t\t\torigins: origins.map(this.toWaypoint),\n\t\t\t\tdestinations: destinations.map(this.toWaypoint),\n\t\t\t\ttravelMode: 'DRIVE',\n\t\t\t\troutingPreference: 'TRAFFIC_AWARE',\n\t\t\t};\n\n\t\t\tconst fieldMask = 'originIndex,destinationIndex,duration,distanceMeters,condition';\n\n\t\t\tconst response = await axios.post(this._routeMatrixURL, body, {\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t'X-Goog-Api-Key': this._apiKey,\n\t\t\t\t\t'X-Goog-FieldMask': fieldMask,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\t// The API returns an array of route elements\n\t\t\tconst results: IRouteMatrixDTO[] = response.data.map((item: RouteMatrixItem) => {\n\t\t\t\tconst distance = this.toDistanceDTO(item.distanceMeters ?? 0);\n\t\t\t\tconst duration = this.toDurationDTO(item.duration ?? '0s');\n\n\t\t\t\treturn {\n\t\t\t\t\tdistance,\n\t\t\t\t\tduration,\n\t\t\t\t\tcondition: item.condition,\n\t\t\t\t\toriginIndex: item.originIndex,\n\t\t\t\t\tdestinationIndex: item.destinationIndex,\n\t\t\t\t};\n\t\t\t});\n\n\t\t\treturn results;\n\t\t} catch (error) {\n\t\t\tconsole.error(`Error in getDistanceMatrix: ${error}`);\n\t\t}\n\n\t\treturn [];\n\t}\n\n\tprivate async getDistanceInfoFromGoogle(origin: ICoordinate, destination: ICoordinate): Promise<IDistanceInfo> {\n\t\ttry {\n\t\t\tconst body = {\n\t\t\t\torigin: this.toLocation(origin),\n\t\t\t\tdestination: this.toLocation(destination),\n\t\t\t\ttravelMode: 'DRIVE',\n\t\t\t\troutingPreference: 'TRAFFIC_AWARE',\n\t\t\t\tcomputeAlternativeRoutes: false,\n\t\t\t\trouteModifiers: {\n\t\t\t\t\tavoidTolls: false,\n\t\t\t\t\tavoidHighways: false,\n\t\t\t\t\tavoidFerries: false,\n\t\t\t\t},\n\t\t\t\tlanguageCode: 'en-US',\n\t\t\t\tunits: 'METRIC',\n\t\t\t};\n\n\t\t\tconst fieldMask = 'routes.duration,routes.distanceMeters';\n\n\t\t\tconst response = await axios.post(this._routeURL, body, {\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t'X-Goog-Api-Key': this._apiKey,\n\t\t\t\t\t'X-Goog-FieldMask': fieldMask,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconst route = response.data.routes[0];\n\n\t\t\tconst distance = this.toDistanceDTO(route.distanceMeters);\n\t\t\tconst duration = this.toDurationDTO(route.duration);\n\n\t\t\treturn { distance, duration };\n\t\t} catch (error) {\n\t\t\tconsole.error(`Error in getDistanceInfo V2: ${error}`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to fetch distance information from Google Maps API.',\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate async getWaypointsDistanceInfoFromGoogle(\n\t\torigin: ICoordinate,\n\t\tdestination: ICoordinate,\n\t\twaypoints: Array<ICoordinate>\n\t): Promise<IWaypointDistanceInfo> {\n\t\ttry {\n\t\t\tconst body = {\n\t\t\t\torigin: this.toLocation(origin),\n\t\t\t\tdestination: this.toLocation(destination),\n\t\t\t\tintermediates: waypoints.map(this.toLocation),\n\t\t\t\ttravelMode: 'DRIVE',\n\t\t\t\troutingPreference: 'TRAFFIC_AWARE',\n\t\t\t\tcomputeAlternativeRoutes: false,\n\t\t\t\trouteModifiers: {\n\t\t\t\t\tavoidTolls: false,\n\t\t\t\t\tavoidHighways: false,\n\t\t\t\t\tavoidFerries: false,\n\t\t\t\t},\n\t\t\t\tlanguageCode: 'en-US',\n\t\t\t\tunits: 'METRIC',\n\t\t\t};\n\n\t\t\tconst fieldMask = 'routes';\n\n\t\t\tconst response = await axios.post(this._routeURL, body, {\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'application/json',\n\t\t\t\t\t'X-Goog-Api-Key': this._apiKey,\n\t\t\t\t\t'X-Goog-FieldMask': fieldMask,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tconst route = response.data.routes[0];\n\n\t\t\tconst distance = this.toDistanceDTO(route.distanceMeters);\n\t\t\tconst duration = this.toDurationDTO(route.duration);\n\t\t\tconst overviewPolyline = polyline.decode(route.polyline.encodedPolyline);\n\n\t\t\tconst legs = (route?.legs ?? []).map(\n\t\t\t\t(leg: { polyline: { encodedPolyline: string }; distanceMeters: number; duration: string }) => {\n\t\t\t\t\tconst overviewPolyline = polyline.decode(leg.polyline.encodedPolyline);\n\n\t\t\t\t\tconst legDistance = this.toDistanceDTO(leg.distanceMeters);\n\t\t\t\t\tconst legDuration = this.toDurationDTO(leg.duration);\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdistance: legDistance,\n\t\t\t\t\t\tduration: legDuration,\n\t\t\t\t\t\toverviewPolyline,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t);\n\n\t\t\treturn { distance, duration, overviewPolyline, legs };\n\t\t} catch (error) {\n\t\t\tconsole.error(`Error in getWaypointDistanceInfo V2: ${error}`);\n\t\t\tthrow new TRPCError({\n\t\t\t\tcode: 'INTERNAL_SERVER_ERROR',\n\t\t\t\tmessage: 'Failed to fetch waypoint distance information from Google Maps API.',\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * Converts an ICoordinate to a location object for Google Maps API\n\t * @param coord - ICoordinate object\n\t * @returns Location object for Google Maps API\n\t */\n\tprivate toLocation(coord: ICoordinate) {\n\t\treturn { location: { latLng: { latitude: coord.latitude, longitude: coord.longitude } } };\n\t}\n\n\t/**\n\t * Converts an ICoordinate to a waypoint object for Google Maps API\n\t * @param coord - ICoordinate object\n\t * @returns Waypoint object for Google Maps API\n\t */\n\tprivate toWaypoint(coord: ICoordinate) {\n\t\treturn { waypoint: { location: { latLng: { latitude: coord.latitude, longitude: coord.longitude } } } };\n\t}\n\n\t/**\n\t * Converts a duration string from Google Maps API to an IDuration object\n\t * @param duration in format \"Xs\" where X is number of seconds\n\t * @returns IDuration object\n\t */\n\tprivate toDurationDTO(duration: string): IDuration {\n\t\tconst durationSeconds = parseInt(duration.replace('s', ''));\n\n\t\tconst hours = Math.floor(durationSeconds / 3600);\n\t\tconst minutes = Math.ceil((durationSeconds % 3600) / 60);\n\n\t\tconst durationText = durationSeconds\n\t\t\t? durationSeconds < 60\n\t\t\t\t? `1 min`\n\t\t\t\t: durationSeconds < 3600\n\t\t\t\t\t? minutes === 1\n\t\t\t\t\t\t? '1 min'\n\t\t\t\t\t\t: `${minutes} mins`\n\t\t\t\t\t: hours === 1\n\t\t\t\t\t\t? minutes === 0\n\t\t\t\t\t\t\t? '1 hour'\n\t\t\t\t\t\t\t: minutes === 1\n\t\t\t\t\t\t\t\t? '1 hour 1 min'\n\t\t\t\t\t\t\t\t: `1 hour ${minutes} mins`\n\t\t\t\t\t\t: minutes === 0\n\t\t\t\t\t\t\t? `${hours} hours`\n\t\t\t\t\t\t\t: minutes === 1\n\t\t\t\t\t\t\t\t? `${hours} hours 1 min`\n\t\t\t\t\t\t\t\t: `${hours} hours ${minutes} mins`\n\t\t\t: '1 min';\n\n\t\treturn { value: durationSeconds, text: durationText };\n\t}\n\n\t/**\n\t * Converts a distance in meters from Google Maps API to an IDistance object\n\t * @param distanceMeters distance in meters\n\t * @returns IDistance object\n\t */\n\tprivate toDistanceDTO(distanceMeters: number): IDistance {\n\t\tconst distanceValue = distanceMeters;\n\t\tconst distanceText = `${(distanceMeters / 1000).toFixed(1)} km`;\n\n\t\treturn { value: distanceValue, text: distanceText };\n\t}\n}\n"]}
@@ -3,18 +3,13 @@ import { AdjustmentReason } from '../../../../utilities/enum';
3
3
  import { Product } from '../product.model';
4
4
  import { LineItem } from '../line-item.model';
5
5
  import { Admin } from '../admin.model';
6
- import { User } from '../user.model';
7
6
  export declare class AdjustedLineItem {
8
7
  lineItem: Ref<LineItem>;
9
8
  note?: string;
10
9
  }
11
- export declare class SuggestedProduct {
12
- user: Ref<User>;
13
- products: Ref<Product>[];
14
- }
15
10
  export declare class AdjustmentInformation {
16
11
  reason?: AdjustmentReason;
17
- suggestedProduct?: SuggestedProduct[];
12
+ suggestedProduct?: Map<string, Ref<Product>[]>;
18
13
  adjustedLineItems?: AdjustedLineItem[];
19
14
  requestedAt?: Date;
20
15
  resolvedAt?: Date;
@@ -9,13 +9,12 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.AdjustmentInformation = exports.SuggestedProduct = exports.AdjustedLineItem = void 0;
12
+ exports.AdjustmentInformation = exports.AdjustedLineItem = void 0;
13
13
  const typegoose_1 = require("@typegoose/typegoose");
14
14
  const enum_1 = require("../../../../utilities/enum");
15
- const product_model_1 = require("../product.model");
16
15
  const line_item_model_1 = require("../line-item.model");
17
16
  const admin_model_1 = require("../admin.model");
18
- const user_model_1 = require("../user.model");
17
+ const mongoose_1 = require("mongoose");
19
18
  class AdjustedLineItem {
20
19
  lineItem;
21
20
  note;
@@ -29,19 +28,6 @@ __decorate([
29
28
  (0, typegoose_1.prop)({ type: String, maxlength: 150 }),
30
29
  __metadata("design:type", String)
31
30
  ], AdjustedLineItem.prototype, "note", void 0);
32
- class SuggestedProduct {
33
- user;
34
- products;
35
- }
36
- exports.SuggestedProduct = SuggestedProduct;
37
- __decorate([
38
- (0, typegoose_1.prop)({ required: true, ref: () => user_model_1.User }),
39
- __metadata("design:type", Object)
40
- ], SuggestedProduct.prototype, "user", void 0);
41
- __decorate([
42
- (0, typegoose_1.prop)({ ref: () => product_model_1.Product, default: [] }),
43
- __metadata("design:type", Array)
44
- ], SuggestedProduct.prototype, "products", void 0);
45
31
  class AdjustmentInformation {
46
32
  reason;
47
33
  suggestedProduct;
@@ -57,8 +43,8 @@ __decorate([
57
43
  __metadata("design:type", String)
58
44
  ], AdjustmentInformation.prototype, "reason", void 0);
59
45
  __decorate([
60
- (0, typegoose_1.prop)({ type: () => [SuggestedProduct], default: [] }),
61
- __metadata("design:type", Array)
46
+ (0, typegoose_1.prop)({ type: () => [mongoose_1.Types.ObjectId] }, typegoose_1.PropType.MAP),
47
+ __metadata("design:type", Map)
62
48
  ], AdjustmentInformation.prototype, "suggestedProduct", void 0);
63
49
  __decorate([
64
50
  (0, typegoose_1.prop)({ type: () => [AdjustedLineItem], default: [] }),
@@ -1 +1 @@
1
- {"version":3,"file":"adjustment-information.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/adjustment-information.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAiD;AACjD,qDAA8D;AAC9D,oDAA2C;AAC3C,wDAA8C;AAC9C,gDAAuC;AACvC,8CAAqC;AAErC,MAAa,gBAAgB;IAErB,QAAQ,CAAiB;IAGzB,IAAI,CAAU;CACrB;AAND,4CAMC;AAJO;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,0BAAQ,EAAE,CAAC;;kDACd;AAGzB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;;8CAClB;AAGtB,MAAa,gBAAgB;IAErB,IAAI,CAAY;IAGhB,QAAQ,CAAiB;CAChC;AAND,4CAMC;AAJO;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,iBAAI,EAAE,CAAC;;8CACnB;AAGhB;IADN,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,uBAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;kDACV;AAEjC,MAAa,qBAAqB;IAE1B,MAAM,CAAoB;IAG1B,gBAAgB,CAAsB;IAGtC,iBAAiB,CAAsB;IAGvC,WAAW,CAAQ;IAGnB,UAAU,CAAQ;IAGlB,KAAK,CAAc;IAGnB,eAAe,CAAW;CACjC;AArBD,sDAqBC;AAnBO;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,uBAAgB,EAAE,CAAC;;qDACd;AAG1B;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,gBAAgB,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;+DACT;AAGtC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,gBAAgB,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;gEACR;AAGvC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;8BAC3B,IAAI;0DAAC;AAGnB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;8BACP,IAAI;yDAAC;AAGlB;IADN,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,mBAAK,EAAE,CAAC;;oDACD;AAGnB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;;8DACP","sourcesContent":["import { prop, Ref } from '@typegoose/typegoose';\nimport { AdjustmentReason } from '../../../../utilities/enum';\nimport { Product } from '../product.model';\nimport { LineItem } from '../line-item.model';\nimport { Admin } from '../admin.model';\nimport { User } from '../user.model';\n\nexport class AdjustedLineItem {\n\t@prop({ required: true, ref: () => LineItem })\n\tpublic lineItem!: Ref<LineItem>;\n\n\t@prop({ type: String, maxlength: 150 })\n\tpublic note?: string;\n}\n\nexport class SuggestedProduct {\n\t@prop({ required: true, ref: () => User })\n\tpublic user: Ref<User>;\n\n\t@prop({ ref: () => Product, default: [] })\n\tpublic products: Ref<Product>[];\n}\nexport class AdjustmentInformation {\n\t@prop({ type: String, enum: AdjustmentReason })\n\tpublic reason?: AdjustmentReason;\n\n\t@prop({ type: () => [SuggestedProduct], default: [] })\n\tpublic suggestedProduct?: SuggestedProduct[];\n\n\t@prop({ type: () => [AdjustedLineItem], default: [] })\n\tpublic adjustedLineItems?: AdjustedLineItem[];\n\n\t@prop({ type: Date, default: () => new Date() })\n\tpublic requestedAt?: Date;\n\n\t@prop({ type: () => Date })\n\tpublic resolvedAt?: Date;\n\n\t@prop({ ref: () => Admin })\n\tpublic admin?: Ref<Admin>;\n\n\t@prop({ type: Boolean, default: false })\n\tpublic isRequestByShop?: boolean;\n}\n"]}
1
+ {"version":3,"file":"adjustment-information.model.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/adjustment-information.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA2D;AAC3D,qDAA8D;AAE9D,wDAA8C;AAC9C,gDAAuC;AAEvC,uCAAiC;AAEjC,MAAa,gBAAgB;IAErB,QAAQ,CAAiB;IAGzB,IAAI,CAAU;CACrB;AAND,4CAMC;AAJO;IADN,IAAA,gBAAI,EAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,0BAAQ,EAAE,CAAC;;kDACd;AAGzB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC;;8CAClB;AAGtB,MAAa,qBAAqB;IAE1B,MAAM,CAAoB;IAG1B,gBAAgB,CAA+B;IAG/C,iBAAiB,CAAsB;IAGvC,WAAW,CAAQ;IAGnB,UAAU,CAAQ;IAGlB,KAAK,CAAc;IAGnB,eAAe,CAAW;CACjC;AArBD,sDAqBC;AAnBO;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,uBAAgB,EAAE,CAAC;;qDACd;AAG1B;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,gBAAK,CAAC,QAAQ,CAAC,EAAE,EAAE,oBAAQ,CAAC,GAAG,CAAC;8BAC3B,GAAG;+DAAyB;AAG/C;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,gBAAgB,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;gEACR;AAGvC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;8BAC3B,IAAI;0DAAC;AAGnB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC;8BACP,IAAI;yDAAC;AAGlB;IADN,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,mBAAK,EAAE,CAAC;;oDACD;AAGnB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;;8DACP","sourcesContent":["import { prop, PropType, Ref } from '@typegoose/typegoose';\nimport { AdjustmentReason } from '../../../../utilities/enum';\nimport { Product } from '../product.model';\nimport { LineItem } from '../line-item.model';\nimport { Admin } from '../admin.model';\nimport { User } from '../user.model';\nimport { Types } from 'mongoose';\n\nexport class AdjustedLineItem {\n\t@prop({ required: true, ref: () => LineItem })\n\tpublic lineItem!: Ref<LineItem>;\n\n\t@prop({ type: String, maxlength: 150 })\n\tpublic note?: string;\n}\n\nexport class AdjustmentInformation {\n\t@prop({ type: String, enum: AdjustmentReason })\n\tpublic reason?: AdjustmentReason;\n\n\t@prop({ type: () => [Types.ObjectId] }, PropType.MAP)\n\tpublic suggestedProduct?: Map<string, Ref<Product>[]>;\n\n\t@prop({ type: () => [AdjustedLineItem], default: [] })\n\tpublic adjustedLineItems?: AdjustedLineItem[];\n\n\t@prop({ type: Date, default: () => new Date() })\n\tpublic requestedAt?: Date;\n\n\t@prop({ type: () => Date })\n\tpublic resolvedAt?: Date;\n\n\t@prop({ ref: () => Admin })\n\tpublic admin?: Ref<Admin>;\n\n\t@prop({ type: Boolean, default: false })\n\tpublic isRequestByShop?: boolean;\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import { Ref } from '@typegoose/typegoose';
2
+ import { WeekDay } from '../../../../utilities/enum';
3
+ import { StartEndTime } from '../shared/work-hour.model';
4
+ import { Zone } from '../zone.model';
5
+ export declare class OrderExtraTimeSlot extends StartEndTime {
6
+ extraTimeInSeconds: number;
7
+ isActive: boolean;
8
+ }
9
+ export declare class OrderExtraTimeSettings {
10
+ day: WeekDay;
11
+ zone: Ref<Zone>;
12
+ slots: OrderExtraTimeSlot[];
13
+ }
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.OrderExtraTimeSettings = exports.OrderExtraTimeSlot = void 0;
13
+ const typegoose_1 = require("@typegoose/typegoose");
14
+ const enum_1 = require("../../../../utilities/enum");
15
+ const work_hour_model_1 = require("../shared/work-hour.model");
16
+ const zone_model_1 = require("../zone.model");
17
+ class OrderExtraTimeSlot extends work_hour_model_1.StartEndTime {
18
+ extraTimeInSeconds;
19
+ isActive;
20
+ }
21
+ exports.OrderExtraTimeSlot = OrderExtraTimeSlot;
22
+ __decorate([
23
+ (0, typegoose_1.Prop)({ type: Number, required: true, min: 0 }),
24
+ __metadata("design:type", Number)
25
+ ], OrderExtraTimeSlot.prototype, "extraTimeInSeconds", void 0);
26
+ __decorate([
27
+ (0, typegoose_1.Prop)({ type: Boolean, default: true }),
28
+ __metadata("design:type", Boolean)
29
+ ], OrderExtraTimeSlot.prototype, "isActive", void 0);
30
+ class OrderExtraTimeSettings {
31
+ day;
32
+ zone;
33
+ slots;
34
+ }
35
+ exports.OrderExtraTimeSettings = OrderExtraTimeSettings;
36
+ __decorate([
37
+ (0, typegoose_1.Prop)({ type: String, enum: enum_1.WeekDay, required: true }),
38
+ __metadata("design:type", Number)
39
+ ], OrderExtraTimeSettings.prototype, "day", void 0);
40
+ __decorate([
41
+ (0, typegoose_1.Prop)({ ref: () => zone_model_1.Zone, required: true }),
42
+ __metadata("design:type", Object)
43
+ ], OrderExtraTimeSettings.prototype, "zone", void 0);
44
+ __decorate([
45
+ (0, typegoose_1.Prop)({ type: [OrderExtraTimeSlot], default: [] }),
46
+ __metadata("design:type", Array)
47
+ ], OrderExtraTimeSettings.prototype, "slots", void 0);
48
+ //# sourceMappingURL=order-extra-time.settings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"order-extra-time.settings.js","sourceRoot":"/","sources":["libraries/mongo/models/embedded/order-extra-time.settings.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAiD;AACjD,qDAAqD;AACrD,+DAAyD;AACzD,8CAAqC;AAErC,MAAa,kBAAmB,SAAQ,8BAAY;IAE5C,kBAAkB,CAAU;IAG5B,QAAQ,CAAU;CACzB;AAND,gDAMC;AAJO;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC;;8DACZ;AAG5B;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;;oDACd;AAG1B,MAAa,sBAAsB;IAE3B,GAAG,CAAW;IAGd,IAAI,CAAa;IAGjB,KAAK,CAAwB;CACpC;AATD,wDASC;AAPO;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,cAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;mDACjC;AAGd;IADN,IAAA,gBAAI,EAAC,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,iBAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;oDAClB;AAGjB;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,CAAC,kBAAkB,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;qDACd","sourcesContent":["import { Prop, Ref } from '@typegoose/typegoose';\nimport { WeekDay } from '../../../../utilities/enum';\nimport { StartEndTime } from '../shared/work-hour.model';\nimport { Zone } from '../zone.model';\n\nexport class OrderExtraTimeSlot extends StartEndTime {\n\t@Prop({ type: Number, required: true, min: 0 })\n\tpublic extraTimeInSeconds!: number;\n\n\t@Prop({ type: Boolean, default: true })\n\tpublic isActive: boolean;\n}\n\nexport class OrderExtraTimeSettings {\n\t@Prop({ type: String, enum: WeekDay, required: true })\n\tpublic day!: WeekDay;\n\n\t@Prop({ ref: () => Zone, required: true })\n\tpublic zone!: Ref<Zone>;\n\n\t@Prop({ type: [OrderExtraTimeSlot], default: [] })\n\tpublic slots!: OrderExtraTimeSlot[];\n}\n"]}
@@ -13,6 +13,7 @@ import { CustomerSupport } from './embedded/customer-support-numbers.model';
13
13
  import { CustomerSupportBatchesSettings } from './embedded/customer-support-batches.model';
14
14
  import { PlusSettings } from './embedded/plus-settings.model';
15
15
  import { AgentNotificationSetting } from './embedded/agent-notification-setting.model';
16
+ import { OrderExtraTimeSettings } from './embedded/order-extra-time.settings';
16
17
  export declare class Setting extends TimeStamps {
17
18
  deliveryCharges: DeliveryCharge[];
18
19
  serviceFeeSetting?: ServiceFeeSetting;
@@ -36,4 +37,5 @@ export declare class Setting extends TimeStamps {
36
37
  plusSettings?: PlusSettings[];
37
38
  agentNotificationSetting?: AgentNotificationSetting;
38
39
  cashbackAmount?: number;
40
+ orderExtraTimeSettings?: OrderExtraTimeSettings[];
39
41
  }
@@ -26,6 +26,7 @@ const customer_support_numbers_model_1 = require("./embedded/customer-support-nu
26
26
  const customer_support_batches_model_1 = require("./embedded/customer-support-batches.model");
27
27
  const plus_settings_model_1 = require("./embedded/plus-settings.model");
28
28
  const agent_notification_setting_model_1 = require("./embedded/agent-notification-setting.model");
29
+ const order_extra_time_settings_1 = require("./embedded/order-extra-time.settings");
29
30
  let Setting = class Setting extends defaultClasses_1.TimeStamps {
30
31
  deliveryCharges;
31
32
  serviceFeeSetting;
@@ -49,6 +50,7 @@ let Setting = class Setting extends defaultClasses_1.TimeStamps {
49
50
  plusSettings;
50
51
  agentNotificationSetting;
51
52
  cashbackAmount;
53
+ orderExtraTimeSettings;
52
54
  };
53
55
  exports.Setting = Setting;
54
56
  __decorate([
@@ -139,6 +141,10 @@ __decorate([
139
141
  (0, typegoose_1.prop)({ type: Number, default: 0 }),
140
142
  __metadata("design:type", Number)
141
143
  ], Setting.prototype, "cashbackAmount", void 0);
144
+ __decorate([
145
+ (0, typegoose_1.prop)({ type: () => [order_extra_time_settings_1.OrderExtraTimeSettings], default: [] }),
146
+ __metadata("design:type", Array)
147
+ ], Setting.prototype, "orderExtraTimeSettings", void 0);
142
148
  exports.Setting = Setting = __decorate([
143
149
  (0, typegoose_1.modelOptions)({ schemaOptions: { collection: 'settings' } })
144
150
  ], Setting);
@@ -1 +1 @@
1
- {"version":3,"file":"setting.model.js","sourceRoot":"/","sources":["libraries/mongo/models/setting.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA0D;AAC1D,4EAAqE;AACrE,kDAAwD;AACxD,sGAA2F;AAC3F,4FAA0E;AAC1E,4EAAkE;AAClE,8EAAoE;AACpE,0EAAgE;AAChE,wEAA8D;AAC9D,oFAAyE;AACzE,8DAA2D;AAC3D,wEAAsE;AACtE,8FAA4E;AAC5E,8FAA2F;AAC3F,wEAA8D;AAE9D,kGAAuF;AAGhF,IAAM,OAAO,GAAb,MAAM,OAAQ,SAAQ,2BAAU;IAE/B,eAAe,CAAmB;IAGlC,iBAAiB,CAAqB;IAGtC,aAAa,CAAiB;IAG9B,eAAe,CAAmB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C,CAAC,kCAAY,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;6CACb;AAG9B;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,2DAAwB,EAAE,CAAC;8BACP,2DAAwB;yDAAC;AAG3D;IADC,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAC,CAAC;;+CACV;kBAjEZ,OAAO;IADnB,IAAA,wBAAY,EAAC,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,CAAC;GAC/C,OAAO,CAkEnB","sourcesContent":["import { modelOptions, prop } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { PaymentMethod } from '../../../utilities/enum';\nimport { BusinessDevelopmentSetting } from './embedded/business-development-setting.model';\nimport { DeliveryCharge } from './embedded/delivery-charge-setting.model';\nimport { CourierSetting } from './embedded/courier-setting.model';\nimport { CurrencySetting } from './embedded/currency-setting.model';\nimport { PayoutSetting } from './embedded/payout-setting.model';\nimport { RiderSetting } from './embedded/rider-setting.model';\nimport { ServiceFeeSetting } from './embedded/service-fee-setting.model';\nimport { WorkHourSetting } from './shared/work-hour.model';\nimport { RiderBatchesSettings } from './embedded/rider-batches.model';\nimport { CustomerSupport } from './embedded/customer-support-numbers.model';\nimport { CustomerSupportBatchesSettings } from './embedded/customer-support-batches.model';\nimport { PlusSettings } from './embedded/plus-settings.model';\nimport { ChargeSetting } from './embedded/charge-settings.model';\nimport { AgentNotificationSetting } from './embedded/agent-notification-setting.model';\n\n@modelOptions({ schemaOptions: { collection: 'settings' } })\nexport class Setting extends TimeStamps {\n\t@prop({ type: () => [DeliveryCharge] })\n\tpublic deliveryCharges: DeliveryCharge[];\n\n\t@prop({ type: ServiceFeeSetting })\n\tpublic serviceFeeSetting?: ServiceFeeSetting;\n\n\t@prop({ type: PayoutSetting })\n\tpublic payoutSetting?: PayoutSetting;\n\n\t@prop({ type: WorkHourSetting })\n\tpublic workHourSetting?: WorkHourSetting;\n\n\t@prop({ type: CourierSetting })\n\tpublic courierSetting?: CourierSetting;\n\n\t@prop({ type: RiderSetting })\n\tpublic riderSetting?: RiderSetting;\n\n\t@prop({ type: BusinessDevelopmentSetting })\n\tpublic businessDevelopmentSetting?: BusinessDevelopmentSetting;\n\n\t@prop({ type: Number, default: Infinity })\n\tpublic payLimitForUser?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic vatPercentage?: number;\n\n\t@prop({ type: () => [Number], default: [] })\n\tpublic riderSearchRanges?: number[];\n\n\t@prop({ type: () => [RiderBatchesSettings], default: [] })\n\tpublic riderBatches?: RiderBatchesSettings[];\n\n\t@prop({ type: Number, default: Infinity })\n\tpublic nearByShopDistance?: number;\n\n\t@prop({ type: Number, default: Infinity })\npublic nearByShopDistanceInHomeScreen?: number;\n\n\t@prop({ type: () => [String], default: [] })\n\tpublic units?: string[];\n\n\t@prop({ type: CurrencySetting })\n\tpublic currencySetting?: CurrencySetting;\n\n\t@prop({ type: () => [String], enum: PaymentMethod, default: [] })\n\tpublic paymentMethods?: PaymentMethod[];\n\n\t@prop({ type: Boolean, default: false })\n\tpublic isGroupOrderEnabled?: boolean;\n\n\t@prop({ type: CustomerSupport })\n\tpublic customerSupport?: CustomerSupport;\n\n\t@prop({ type: () => [CustomerSupportBatchesSettings], default: [] })\n\tpublic customerSupportBatches?: CustomerSupportBatchesSettings[];\n\n\t@prop({ type: () => [PlusSettings], default: [] })\n\tpublic plusSettings?: PlusSettings[];\n\n\t@prop({ type: AgentNotificationSetting })\n\tpublic agentNotificationSetting?: AgentNotificationSetting;\n\n\t@prop({ type: Number, default: 0})\n\tcashbackAmount?: number;\n}\n"]}
1
+ {"version":3,"file":"setting.model.js","sourceRoot":"/","sources":["libraries/mongo/models/setting.model.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAA0D;AAC1D,4EAAqE;AACrE,kDAAwD;AACxD,sGAA2F;AAC3F,4FA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I,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;;oDACH;AAG9B;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,gDAAe,EAAE,CAAC;8BACP,gDAAe;gDAAC;AAGlC;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,+DAA8B,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;uDACH;AAG1D;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,kCAAY,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;6CACb;AAG9B;IADN,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,2DAAwB,EAAE,CAAC;8BACP,2DAAwB;yDAAC;AAG3D;IADC,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;;+CACX;AAGxB;IADC,IAAA,gBAAI,EAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,kDAAsB,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;;uDACV;kBApEtC,OAAO;IADnB,IAAA,wBAAY,EAAC,EAAE,aAAa,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE,EAAE,CAAC;GAC/C,OAAO,CAqEnB","sourcesContent":["import { modelOptions, prop } from '@typegoose/typegoose';\nimport { TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';\nimport { PaymentMethod } from '../../../utilities/enum';\nimport { BusinessDevelopmentSetting } from './embedded/business-development-setting.model';\nimport { DeliveryCharge } from './embedded/delivery-charge-setting.model';\nimport { CourierSetting } from './embedded/courier-setting.model';\nimport { CurrencySetting } from './embedded/currency-setting.model';\nimport { PayoutSetting } from './embedded/payout-setting.model';\nimport { RiderSetting } from './embedded/rider-setting.model';\nimport { ServiceFeeSetting } from './embedded/service-fee-setting.model';\nimport { WorkHourSetting } from './shared/work-hour.model';\nimport { RiderBatchesSettings } from './embedded/rider-batches.model';\nimport { CustomerSupport } from './embedded/customer-support-numbers.model';\nimport { CustomerSupportBatchesSettings } from './embedded/customer-support-batches.model';\nimport { PlusSettings } from './embedded/plus-settings.model';\nimport { AgentNotificationSetting } from './embedded/agent-notification-setting.model';\nimport { OrderExtraTimeSettings } from './embedded/order-extra-time.settings';\n\n@modelOptions({ schemaOptions: { collection: 'settings' } })\nexport class Setting extends TimeStamps {\n\t@prop({ type: () => [DeliveryCharge] })\n\tpublic deliveryCharges: DeliveryCharge[];\n\n\t@prop({ type: ServiceFeeSetting })\n\tpublic serviceFeeSetting?: ServiceFeeSetting;\n\n\t@prop({ type: PayoutSetting })\n\tpublic payoutSetting?: PayoutSetting;\n\n\t@prop({ type: WorkHourSetting })\n\tpublic workHourSetting?: WorkHourSetting;\n\n\t@prop({ type: CourierSetting })\n\tpublic courierSetting?: CourierSetting;\n\n\t@prop({ type: RiderSetting })\n\tpublic riderSetting?: RiderSetting;\n\n\t@prop({ type: BusinessDevelopmentSetting })\n\tpublic businessDevelopmentSetting?: BusinessDevelopmentSetting;\n\n\t@prop({ type: Number, default: Infinity })\n\tpublic payLimitForUser?: number;\n\n\t@prop({ type: Number, default: 0 })\n\tpublic vatPercentage?: number;\n\n\t@prop({ type: () => [Number], default: [] })\n\tpublic riderSearchRanges?: number[];\n\n\t@prop({ type: () => [RiderBatchesSettings], default: [] })\n\tpublic riderBatches?: RiderBatchesSettings[];\n\n\t@prop({ type: Number, default: Infinity })\n\tpublic nearByShopDistance?: number;\n\n\t@prop({ type: Number, default: Infinity })\n\tpublic nearByShopDistanceInHomeScreen?: number;\n\n\t@prop({ type: () => [String], default: [] })\n\tpublic units?: string[];\n\n\t@prop({ type: CurrencySetting })\n\tpublic currencySetting?: CurrencySetting;\n\n\t@prop({ type: () => [String], enum: PaymentMethod, default: [] })\n\tpublic paymentMethods?: PaymentMethod[];\n\n\t@prop({ type: Boolean, default: false })\n\tpublic isGroupOrderEnabled?: boolean;\n\n\t@prop({ type: CustomerSupport })\n\tpublic customerSupport?: CustomerSupport;\n\n\t@prop({ type: () => [CustomerSupportBatchesSettings], default: [] })\n\tpublic customerSupportBatches?: CustomerSupportBatchesSettings[];\n\n\t@prop({ type: () => [PlusSettings], default: [] })\n\tpublic plusSettings?: PlusSettings[];\n\n\t@prop({ type: AgentNotificationSetting })\n\tpublic agentNotificationSetting?: AgentNotificationSetting;\n\n\t@prop({ type: Number, default: 0 })\n\tcashbackAmount?: number;\n\n\t@prop({ type: () => [OrderExtraTimeSettings], default: [] })\n\torderExtraTimeSettings?: OrderExtraTimeSettings[];\n}\n"]}
@@ -1,13 +1,4 @@
1
- import { Coordinate, DistanceResult, OSRMConfig, OSRMOptions } from './types';
2
1
  export * from './types';
3
2
  export * from './enums';
4
- export declare class OSRMService {
5
- private readonly baseUrl;
6
- private readonly timeout;
7
- private readonly headers;
8
- constructor(config?: OSRMConfig);
9
- getDistance(source: Coordinate, destinations: Coordinate[], options?: OSRMOptions): Promise<DistanceResult[]>;
10
- private buildUrl;
11
- private parseResponse;
12
- private fetch;
13
- }
3
+ export { OSRMClient } from './osrm-client';
4
+ export { OSRMService } from './osrm-service';
@@ -10,103 +10,15 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
14
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
15
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
16
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
17
- return c > 3 && r && Object.defineProperty(target, key, r), r;
18
- };
19
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
15
  };
22
- var __metadata = (this && this.__metadata) || function (k, v) {
23
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
24
- };
25
16
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.OSRMService = void 0;
27
- const typedi_1 = require("typedi");
28
- const enums_1 = require("./enums");
17
+ exports.OSRMService = exports.OSRMClient = void 0;
29
18
  __exportStar(require("./types"), exports);
30
19
  __exportStar(require("./enums"), exports);
31
- let OSRMService = class OSRMService {
32
- baseUrl;
33
- timeout;
34
- headers;
35
- constructor(config) {
36
- const envUrls = {
37
- development: 'https://api-v2-development.lyxa.ai/distance',
38
- staging: 'https://api-v2-staging.lyxa.ai/distance',
39
- production: 'https://api-v2.lyxa.ai/distance',
40
- };
41
- const env = process.env.NODE_ENV ?? 'development';
42
- this.baseUrl = config?.baseUrl ?? envUrls[env] ?? envUrls.development;
43
- this.timeout = config?.timeout ?? 10000;
44
- this.headers = { Accept: 'application/json', ...config?.headers };
45
- }
46
- async getDistance(source, destinations, options) {
47
- if (!destinations.length)
48
- return [];
49
- const profile = options?.profile ?? enums_1.OSRMProfile.BIKE;
50
- const version = options?.version ?? 'v1';
51
- const url = this.buildUrl(source, destinations, profile, version);
52
- const data = await this.fetch(url);
53
- return this.parseResponse(data, destinations);
54
- }
55
- buildUrl(source, destinations, profile, version) {
56
- const coords = [source, ...destinations].map(([lon, lat]) => `${lon},${lat}`).join(';');
57
- const indices = destinations.map((_, i) => i + 1).join(';');
58
- return `${this.baseUrl}/table/${version}/${profile}/${coords}.json?sources=0&destinations=${indices}&annotations=distance,duration`;
59
- }
60
- parseResponse(data, destinations) {
61
- const distances = data.distances?.[0];
62
- const durations = data.durations?.[0];
63
- if (!distances || !durations) {
64
- throw new Error('Invalid OSRM response: missing distance or duration data');
65
- }
66
- return destinations.map((point, i) => {
67
- const meters = distances[i];
68
- const seconds = durations[i];
69
- if (meters === null || seconds === null) {
70
- throw new Error(`No route found for destination ${i + 1} of ${destinations.length}`);
71
- }
72
- return {
73
- point,
74
- distanceKm: +(meters / 1000).toFixed(2),
75
- durationMin: +(seconds / 60).toFixed(1),
76
- };
77
- });
78
- }
79
- async fetch(url) {
80
- const controller = new AbortController();
81
- const timeoutId = setTimeout(() => controller.abort(), this.timeout);
82
- try {
83
- const response = await fetch(url, {
84
- signal: controller.signal,
85
- headers: this.headers,
86
- });
87
- if (!response.ok) {
88
- throw new Error(`OSRM API error: ${response.status} ${response.statusText}`);
89
- }
90
- const data = await response.json();
91
- if (data.code !== enums_1.OSRMCode.OK) {
92
- throw new Error(`OSRM error: ${data.code}${data.message ? ` - ${data.message}` : ''}`);
93
- }
94
- return data;
95
- }
96
- catch (error) {
97
- if (error instanceof Error && error.name === 'AbortError') {
98
- throw new Error(`OSRM request timeout after ${this.timeout}ms`);
99
- }
100
- throw error;
101
- }
102
- finally {
103
- clearTimeout(timeoutId);
104
- }
105
- }
106
- };
107
- exports.OSRMService = OSRMService;
108
- exports.OSRMService = OSRMService = __decorate([
109
- (0, typedi_1.Service)(),
110
- __metadata("design:paramtypes", [Object])
111
- ], OSRMService);
20
+ var osrm_client_1 = require("./osrm-client");
21
+ Object.defineProperty(exports, "OSRMClient", { enumerable: true, get: function () { return osrm_client_1.OSRMClient; } });
22
+ var osrm_service_1 = require("./osrm-service");
23
+ Object.defineProperty(exports, "OSRMService", { enumerable: true, get: function () { return osrm_service_1.OSRMService; } });
112
24
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/osrm/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAAiC;AAEjC,mCAAgD;AAEhD,0CAAwB;AACxB,0CAAwB;AAGjB,IAAM,WAAW,GAAjB,MAAM,WAAW;IACN,OAAO,CAAS;IAChB,OAAO,CAAS;IAChB,OAAO,CAAyB;IAEjD,YAAY,MAAmB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cesContent":["import { Service } from 'typedi';\nimport { Coordinate, DistanceResult, OSRMConfig, OSRMOptions, TableResponse } from './types';\nimport { OSRMCode, OSRMProfile } from './enums';\n\nexport * from './types';\nexport * from './enums';\n\n@Service()\nexport class OSRMService {\n\tprivate readonly baseUrl: string;\n\tprivate readonly timeout: number;\n\tprivate readonly headers: Record<string, string>;\n\n\tconstructor(config?: OSRMConfig) {\n\t\tconst envUrls = {\n\t\t\tdevelopment: 'https://api-v2-development.lyxa.ai/distance',\n\t\t\tstaging: 'https://api-v2-staging.lyxa.ai/distance',\n\t\t\tproduction: 'https://api-v2.lyxa.ai/distance',\n\t\t} as const;\n\n\t\tconst env = (process.env.NODE_ENV as keyof typeof envUrls) ?? 'development';\n\t\tthis.baseUrl = config?.baseUrl ?? envUrls[env] ?? envUrls.development;\n\t\tthis.timeout = config?.timeout ?? 10000;\n\t\tthis.headers = { Accept: 'application/json', ...config?.headers };\n\t}\n\n\tasync getDistance(\n\t\tsource: Coordinate,\n\t\tdestinations: Coordinate[],\n\t\toptions?: OSRMOptions\n\t): Promise<DistanceResult[]> {\n\t\tif (!destinations.length) return [];\n\n\t\tconst profile = options?.profile ?? OSRMProfile.BIKE;\n\t\tconst version = options?.version ?? 'v1';\n\n\t\tconst url = this.buildUrl(source, destinations, profile, version);\n\t\tconst data = await this.fetch(url);\n\n\t\treturn this.parseResponse(data, destinations);\n\t}\n\n\tprivate buildUrl(source: Coordinate, destinations: Coordinate[], profile: OSRMProfile, version: string): string {\n\t\tconst coords = [source, ...destinations].map(([lon, lat]) => `${lon},${lat}`).join(';');\n\t\tconst indices = destinations.map((_, i) => i + 1).join(';');\n\t\treturn `${this.baseUrl}/table/${version}/${profile}/${coords}.json?sources=0&destinations=${indices}&annotations=distance,duration`;\n\t}\n\n\tprivate parseResponse(data: TableResponse, destinations: Coordinate[]): DistanceResult[] {\n\t\tconst distances = data.distances?.[0];\n\t\tconst durations = data.durations?.[0];\n\n\t\tif (!distances || !durations) {\n\t\t\tthrow new Error('Invalid OSRM response: missing distance or duration data');\n\t\t}\n\n\t\treturn destinations.map((point, i) => {\n\t\t\tconst meters = distances[i];\n\t\t\tconst seconds = durations[i];\n\n\t\t\tif (meters === null || seconds === null) {\n\t\t\t\tthrow new Error(`No route found for destination ${i + 1} of ${destinations.length}`);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tpoint,\n\t\t\t\tdistanceKm: +(meters / 1000).toFixed(2),\n\t\t\t\tdurationMin: +(seconds / 60).toFixed(1),\n\t\t\t};\n\t\t});\n\t}\n\n\tprivate async fetch(url: string): Promise<TableResponse> {\n\t\tconst controller = new AbortController();\n\t\tconst timeoutId = setTimeout(() => controller.abort(), this.timeout);\n\n\t\ttry {\n\t\t\tconst response = await fetch(url, {\n\t\t\t\tsignal: controller.signal,\n\t\t\t\theaders: this.headers,\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`OSRM API error: ${response.status} ${response.statusText}`);\n\t\t\t}\n\n\t\t\tconst data = await response.json();\n\n\t\t\tif (data.code !== OSRMCode.OK) {\n\t\t\t\tthrow new Error(`OSRM error: ${data.code}${data.message ? ` - ${data.message}` : ''}`);\n\t\t\t}\n\n\t\t\treturn data;\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error && error.name === 'AbortError') {\n\t\t\t\tthrow new Error(`OSRM request timeout after ${this.timeout}ms`);\n\t\t\t}\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tclearTimeout(timeoutId);\n\t\t}\n\t}\n}\n\n "]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["libraries/osrm/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,0CAAwB;AACxB,0CAAwB;AAGxB,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AAGnB,+CAA6C;AAApC,2GAAA,WAAW,OAAA","sourcesContent":["// Export types and enums\nexport * from './types';\nexport * from './enums';\n\n// Export low-level client\nexport { OSRMClient } from './osrm-client';\n\n// Export high-level service\nexport { OSRMService } from './osrm-service';\n"]}
@@ -0,0 +1,16 @@
1
+ import { OSRMProfile } from './enums';
2
+ import { Coordinate, OSRMConfig, TableResponse } from './types';
3
+ export declare class OSRMClient {
4
+ private readonly baseUrl;
5
+ private readonly timeout;
6
+ private readonly headers;
7
+ constructor(config?: OSRMConfig);
8
+ table(source: Coordinate, destinations: Coordinate[], profile?: OSRMProfile, version?: string): Promise<TableResponse>;
9
+ private buildTableUrl;
10
+ private fetch;
11
+ parseTableResponse(response: TableResponse, destinations: Coordinate[]): Array<{
12
+ point: Coordinate;
13
+ distanceKm: number;
14
+ durationMin: number;
15
+ }>;
16
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OSRMClient = void 0;
4
+ const enums_1 = require("./enums");
5
+ class OSRMClient {
6
+ baseUrl;
7
+ timeout;
8
+ headers;
9
+ constructor(config) {
10
+ const urls = {
11
+ development: 'https://api-v2-development.lyxa.ai/distance',
12
+ staging: 'https://api-v2-staging.lyxa.ai/distance',
13
+ preprod: 'https://api-v2-preprod.lyxa.ai/distance',
14
+ production: 'https://api-v2.lyxa.ai/distance',
15
+ };
16
+ const env = process.env.NODE_ENV ?? 'development';
17
+ this.baseUrl = config?.baseUrl ?? urls[env] ?? urls.development;
18
+ this.timeout = config?.timeout ?? 10000;
19
+ this.headers = { Accept: 'application/json', ...config?.headers };
20
+ }
21
+ async table(source, destinations, profile = enums_1.OSRMProfile.BIKE, version = 'v1') {
22
+ if (!destinations.length) {
23
+ throw new Error('Destinations array cannot be empty');
24
+ }
25
+ const url = this.buildTableUrl(source, destinations, profile, version);
26
+ return this.fetch(url);
27
+ }
28
+ buildTableUrl(source, destinations, profile, version) {
29
+ const coords = [source, ...destinations].map(([lon, lat]) => `${lon},${lat}`).join(';');
30
+ const indices = destinations.map((_, i) => i + 1).join(';');
31
+ return `${this.baseUrl}/table/${version}/${profile}/${coords}.json?sources=0&destinations=${indices}&annotations=distance,duration`;
32
+ }
33
+ async fetch(url) {
34
+ const controller = new AbortController();
35
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
36
+ try {
37
+ const response = await fetch(url, {
38
+ signal: controller.signal,
39
+ headers: this.headers,
40
+ });
41
+ if (!response.ok) {
42
+ throw new Error(`OSRM API error: ${response.status} ${response.statusText}`);
43
+ }
44
+ const data = await response.json();
45
+ if (data.code !== enums_1.OSRMCode.OK) {
46
+ throw new Error(`OSRM error: ${data.code}${data.message ? ` - ${data.message}` : ''}`);
47
+ }
48
+ return data;
49
+ }
50
+ catch (error) {
51
+ if (error instanceof Error && error.name === 'AbortError') {
52
+ throw new Error(`OSRM request timeout after ${this.timeout}ms`);
53
+ }
54
+ throw error;
55
+ }
56
+ finally {
57
+ clearTimeout(timeoutId);
58
+ }
59
+ }
60
+ parseTableResponse(response, destinations) {
61
+ const distances = response.distances?.[0];
62
+ const durations = response.durations?.[0];
63
+ if (!distances || !durations) {
64
+ throw new Error('Invalid OSRM response: missing distance or duration data');
65
+ }
66
+ return destinations.map((point, i) => {
67
+ const meters = distances[i];
68
+ const seconds = durations[i];
69
+ if (meters === null || seconds === null) {
70
+ throw new Error(`No route found for destination ${i + 1} of ${destinations.length}`);
71
+ }
72
+ return {
73
+ point,
74
+ distanceKm: +(meters / 1000).toFixed(2),
75
+ durationMin: +(seconds / 60).toFixed(1),
76
+ };
77
+ });
78
+ }
79
+ }
80
+ exports.OSRMClient = OSRMClient;
81
+ //# sourceMappingURL=osrm-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"osrm-client.js","sourceRoot":"/","sources":["libraries/osrm/osrm-client.ts"],"names":[],"mappings":";;;AAAA,mCAAgD;AAOhD,MAAa,UAAU;IACL,OAAO,CAAS;IAChB,OAAO,CAAS;IAChB,OAAO,CAAyB;IAEjD,YAAY,MAAmB;QAC9B,MAAM,IAAI,GAAG;YACZ,WAAW,EAAE,6CAA6C;YAC1D,OAAO,EAAE,yCAAyC;YAClD,OAAO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AC,SAAS,CAAC,CAAC;QACzB,CAAC;IACF,CAAC;IAKM,kBAAkB,CACxB,QAAuB,EACvB,YAA0B;QAE1B,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;QAC1C,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;QAE1C,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;QAC7E,CAAC;QAED,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;YACpC,MAAM,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YAC5B,MAAM,OAAO,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;YAE7B,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;gBACzC,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,GAAG,CAAC,OAAO,YAAY,CAAC,MAAM,EAAE,CAAC,CAAC;YACtF,CAAC;YAED,OAAO;gBACN,KAAK;gBACL,UAAU,EAAE,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;gBACvC,WAAW,EAAE,CAAC,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;aACvC,CAAC;QACH,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AAlHD,gCAkHC","sourcesContent":["import { OSRMCode, OSRMProfile } from './enums';\nimport { Coordinate, OSRMConfig, TableResponse } from './types';\n\n/**\n * Low-level OSRM HTTP client\n * Handles direct API communication without business logic\n */\nexport class OSRMClient {\n\tprivate readonly baseUrl: string;\n\tprivate readonly timeout: number;\n\tprivate readonly headers: Record<string, string>;\n\n\tconstructor(config?: OSRMConfig) {\n\t\tconst urls = {\n\t\t\tdevelopment: 'https://api-v2-development.lyxa.ai/distance',\n\t\t\tstaging: 'https://api-v2-staging.lyxa.ai/distance',\n\t\t\tpreprod: 'https://api-v2-preprod.lyxa.ai/distance',\n\t\t\tproduction: 'https://api-v2.lyxa.ai/distance',\n\t\t} as const;\n\n\t\tconst env = (process.env.NODE_ENV as keyof typeof urls) ?? 'development';\n\t\tthis.baseUrl = config?.baseUrl ?? urls[env] ?? urls.development;\n\t\tthis.timeout = config?.timeout ?? 10000;\n\t\tthis.headers = { Accept: 'application/json', ...config?.headers };\n\t}\n\n\t/**\n\t * Call OSRM table API to get distances and durations\n\t * @returns Raw OSRM response\n\t */\n\tasync table(\n\t\tsource: Coordinate,\n\t\tdestinations: Coordinate[],\n\t\tprofile: OSRMProfile = OSRMProfile.BIKE,\n\t\tversion: string = 'v1'\n\t): Promise<TableResponse> {\n\t\tif (!destinations.length) {\n\t\t\tthrow new Error('Destinations array cannot be empty');\n\t\t}\n\n\t\tconst url = this.buildTableUrl(source, destinations, profile, version);\n\t\treturn this.fetch(url);\n\t}\n\n\t/**\n\t * Build OSRM table API URL\n\t */\n\tprivate buildTableUrl(\n\t\tsource: Coordinate,\n\t\tdestinations: Coordinate[],\n\t\tprofile: OSRMProfile,\n\t\tversion: string\n\t): string {\n\t\tconst coords = [source, ...destinations].map(([lon, lat]) => `${lon},${lat}`).join(';');\n\t\tconst indices = destinations.map((_, i) => i + 1).join(';');\n\t\treturn `${this.baseUrl}/table/${version}/${profile}/${coords}.json?sources=0&destinations=${indices}&annotations=distance,duration`;\n\t}\n\n\t/**\n\t * HTTP fetch with timeout and error handling\n\t */\n\tprivate async fetch(url: string): Promise<TableResponse> {\n\t\tconst controller = new AbortController();\n\t\tconst timeoutId = setTimeout(() => controller.abort(), this.timeout);\n\n\t\ttry {\n\t\t\tconst response = await fetch(url, {\n\t\t\t\tsignal: controller.signal,\n\t\t\t\theaders: this.headers,\n\t\t\t});\n\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`OSRM API error: ${response.status} ${response.statusText}`);\n\t\t\t}\n\n\t\t\tconst data = await response.json();\n\n\t\t\tif (data.code !== OSRMCode.OK) {\n\t\t\t\tthrow new Error(`OSRM error: ${data.code}${data.message ? ` - ${data.message}` : ''}`);\n\t\t\t}\n\n\t\t\treturn data;\n\t\t} catch (error) {\n\t\t\tif (error instanceof Error && error.name === 'AbortError') {\n\t\t\t\tthrow new Error(`OSRM request timeout after ${this.timeout}ms`);\n\t\t\t}\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tclearTimeout(timeoutId);\n\t\t}\n\t}\n\n\t/**\n\t * Parse raw OSRM response into structured data\n\t */\n\tpublic parseTableResponse(\n\t\tresponse: TableResponse,\n\t\tdestinations: Coordinate[]\n\t): Array<{ point: Coordinate; distanceKm: number; durationMin: number }> {\n\t\tconst distances = response.distances?.[0];\n\t\tconst durations = response.durations?.[0];\n\n\t\tif (!distances || !durations) {\n\t\t\tthrow new Error('Invalid OSRM response: missing distance or duration data');\n\t\t}\n\n\t\treturn destinations.map((point, i) => {\n\t\t\tconst meters = distances[i];\n\t\t\tconst seconds = durations[i];\n\n\t\t\tif (meters === null || seconds === null) {\n\t\t\t\tthrow new Error(`No route found for destination ${i + 1} of ${destinations.length}`);\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\tpoint,\n\t\t\t\tdistanceKm: +(meters / 1000).toFixed(2),\n\t\t\t\tdurationMin: +(seconds / 60).toFixed(1),\n\t\t\t};\n\t\t});\n\t}\n}\n"]}
@@ -0,0 +1,8 @@
1
+ import { Coordinate, DistanceResult, OSRMConfig, OSRMOptions } from './types';
2
+ export declare class OSRMService {
3
+ private readonly client;
4
+ private readonly DEFAULT_EXTRA_TIME;
5
+ constructor(config?: OSRMConfig);
6
+ getDistance(source: Coordinate, dest: Coordinate | Coordinate[], options?: OSRMOptions): Promise<DistanceResult | DistanceResult[]>;
7
+ private getExtraTime;
8
+ }
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.OSRMService = void 0;
16
+ const dayjs_1 = __importDefault(require("dayjs"));
17
+ const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
18
+ const typedi_1 = require("typedi");
19
+ const index_1 = require("../../index");
20
+ const time_1 = require("../../utilities/time");
21
+ const enums_1 = require("./enums");
22
+ const osrm_client_1 = require("./osrm-client");
23
+ let OSRMService = class OSRMService {
24
+ client;
25
+ DEFAULT_EXTRA_TIME = 10;
26
+ constructor(config) {
27
+ this.client = new osrm_client_1.OSRMClient(config);
28
+ }
29
+ async getDistance(source, dest, options) {
30
+ const isArray = Array.isArray(dest);
31
+ const destinations = isArray ? dest : [dest];
32
+ if (!destinations.length)
33
+ return [];
34
+ const response = await this.client.table(source, destinations, options?.profile ?? enums_1.OSRMProfile.BIKE, options?.version ?? 'v1');
35
+ const distances = this.client.parseTableResponse(response, destinations);
36
+ const extraTimeSec = await this.getExtraTime();
37
+ const results = distances.map(d => ({
38
+ ...d,
39
+ durationMin: +(d.durationMin + extraTimeSec / 60).toFixed(1),
40
+ }));
41
+ return isArray ? results : results[0];
42
+ }
43
+ async getExtraTime() {
44
+ const settings = await (0, index_1.getLibraries)().getCachedSettingsService().getSettings();
45
+ dayjs_1.default.extend(timezone_1.default);
46
+ const now = (0, dayjs_1.default)().tz(time_1.LyxaTimezone);
47
+ const today = now.day();
48
+ const currentTime = now.format('HH:mm');
49
+ const daySetting = settings.orderExtraTimeSettings?.find(s => s.day === today);
50
+ if (!daySetting)
51
+ return this.DEFAULT_EXTRA_TIME;
52
+ const slot = daySetting.slots.find(s => s.isActive && s.start <= currentTime && s.end >= currentTime);
53
+ return slot?.extraTimeInSeconds ?? this.DEFAULT_EXTRA_TIME;
54
+ }
55
+ };
56
+ exports.OSRMService = OSRMService;
57
+ exports.OSRMService = OSRMService = __decorate([
58
+ (0, typedi_1.Service)(),
59
+ __metadata("design:paramtypes", [Object])
60
+ ], OSRMService);
61
+ //# sourceMappingURL=osrm-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"osrm-service.js","sourceRoot":"/","sources":["libraries/osrm/osrm-service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAA0B;AAC1B,qEAA6C;AAC7C,mCAAiC;AACjC,uCAA2C;AAE3C,+CAAoD;AAEpD,mCAAsC;AACtC,+CAA2C;AAIpC,IAAM,WAAW,GAAjB,MAAM,WAAW;IACN,MAAM,CAAa;IACnB,kBAAkB,GAAG,EAAE,CAAC;IAEzC,YAAY,MAAmB;QAC9B,IAAI,CAAC,MAAM,GAAG,IAAI,wBAAU,CAAC,MAAM,CAAC,CAAC;IACtC,CAAC;IAEM,KAAK,CAAC,WAAW,CACvB,MAAkB,EAClB,IAA+B,EAC/B,OAAqB;QAErB,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACpC,MAAM,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAE7C,IAAI,CAAC,YAAY,CAAC,MAAM;YAAE,OAAO,EAAE,CAAC;QACpC,MAAM,QAAQ,GAAG,MAAM,IAAI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C,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,KAAK,IAAI,WAAW,IAAI,CAAC,CAAC,GAAG,IAAI,WAAW,CAAC,CAAC;QACtG,OAAO,IAAI,EAAE,kBAAkB,IAAI,IAAI,CAAC,kBAAkB,CAAC;IAC5D,CAAC;CACD,CAAA;AA/CY,kCAAW;sBAAX,WAAW;IADvB,IAAA,gBAAO,GAAE;;GACG,WAAW,CA+CvB","sourcesContent":["import dayjs from 'dayjs';\nimport timezone from 'dayjs/plugin/timezone';\nimport { Service } from 'typedi';\nimport { getLibraries } from '../../index';\nimport { WeekDay } from '../../utilities/enum';\nimport { LyxaTimezone } from '../../utilities/time';\nimport { Setting } from '../mongo/models';\nimport { OSRMProfile } from './enums';\nimport { OSRMClient } from './osrm-client';\nimport { Coordinate, DistanceResult, OSRMConfig, OSRMOptions } from './types';\n\n@Service()\nexport class OSRMService {\n\tprivate readonly client: OSRMClient;\n\tprivate readonly DEFAULT_EXTRA_TIME = 10;\n\n\tconstructor(config?: OSRMConfig) {\n\t\tthis.client = new OSRMClient(config);\n\t}\n\n\tpublic async getDistance(\n\t\tsource: Coordinate,\n\t\tdest: Coordinate | Coordinate[],\n\t\toptions?: OSRMOptions\n\t): Promise<DistanceResult | DistanceResult[]> {\n\t\tconst isArray = Array.isArray(dest);\n\t\tconst destinations = isArray ? dest : [dest];\n\n\t\tif (!destinations.length) return [];\n\t\tconst response = await this.client.table(\n\t\t\tsource,\n\t\t\tdestinations,\n\t\t\toptions?.profile ?? OSRMProfile.BIKE,\n\t\t\toptions?.version ?? 'v1'\n\t\t);\n\n\t\tconst distances = this.client.parseTableResponse(response, destinations);\n\t\tconst extraTimeSec = await this.getExtraTime();\n\t\tconst results = distances.map(d => ({\n\t\t\t...d,\n\t\t\tdurationMin: +(d.durationMin + extraTimeSec / 60).toFixed(1),\n\t\t}));\n\t\treturn isArray ? results : results[0];\n\t}\n\n\tprivate async getExtraTime(): Promise<number> {\n\t\tconst settings: Setting = await getLibraries().getCachedSettingsService().getSettings();\n\t\tdayjs.extend(timezone);\n\n\t\tconst now = dayjs().tz(LyxaTimezone);\n\t\tconst today = now.day() as WeekDay;\n\t\tconst currentTime = now.format('HH:mm');\n\n\t\tconst daySetting = settings.orderExtraTimeSettings?.find(s => s.day === today);\n\t\tif (!daySetting) return this.DEFAULT_EXTRA_TIME;\n\n\t\tconst slot = daySetting.slots.find(s => s.isActive && s.start <= currentTime && s.end >= currentTime);\n\t\treturn slot?.extraTimeInSeconds ?? this.DEFAULT_EXTRA_TIME;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"/","sources":["libraries/osrm/types.ts"],"names":[],"mappings":"","sourcesContent":["import { OSRMCode, OSRMProfile } from './enums';\n\nexport type Longitude = number;\nexport type Latitude = number;\nexport type Coordinate = readonly [longitude: Longitude, latitude: Latitude];\n\nexport interface OSRMOptions {\n\treadonly profile?: OSRMProfile;\n\treadonly version?: string;\n}\n\nexport interface OSRMConfig {\n\treadonly baseUrl?: string;\n\treadonly timeout?: number;\n\treadonly headers?: Readonly<Record<string, string>>;\n}\n\nexport interface TableResponse {\n\treadonly code: OSRMCode;\n\treadonly message?: string;\n\treadonly durations?: ReadonlyArray<ReadonlyArray<number | null>>;\n\treadonly distances?: ReadonlyArray<ReadonlyArray<number | null>>;\n}\n\nexport interface DistanceResult {\n\treadonly point: Coordinate;\n\treadonly distanceKm: number;\n\treadonly durationMin: number;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"/","sources":["libraries/osrm/types.ts"],"names":[],"mappings":"","sourcesContent":["import { OSRMCode, OSRMProfile } from './enums';\n\nexport type Longitude = number;\nexport type Latitude = number;\nexport type Coordinate = readonly [longitude: Longitude, latitude: Latitude];\n\nexport interface OSRMOptions {\n\treadonly profile?: OSRMProfile;\n\treadonly version?: string;\n}\n\nexport interface OSRMConfig {\n\treadonly baseUrl?: string;\n\treadonly timeout?: number;\n\treadonly headers?: Readonly<Record<string, string>>;\n}\n\nexport interface TableResponse {\n\treadonly code: OSRMCode;\n\treadonly message?: string;\n\treadonly durations?: ReadonlyArray<ReadonlyArray<number | null>>;\n\treadonly distances?: ReadonlyArray<ReadonlyArray<number | null>>;\n}\n\nexport interface DistanceResult {\n\treadonly point: Coordinate;\n\treadonly distanceKm: number;\n\treadonly durationMin: number;\n}\n"]}
@@ -22,7 +22,7 @@ Perfect for sharing types between frontend and backend applications.
22
22
 
23
23
  ## Version
24
24
 
25
- Version: 1.2.25
25
+ Version: 1.2.27
26
26
 
27
27
  ## Dependencies
28
28
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/types",
3
- "version": "1.2.25",
3
+ "version": "1.2.27",
4
4
  "description": "Lyxa type definitions and validation schemas for both frontend and backend",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -1,2 +1,3 @@
1
1
  export * from './currency';
2
2
  export * from './nutritions';
3
+ export * from './common-methods';
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./currency"), exports);
18
18
  __exportStar(require("./nutritions"), exports);
19
+ __exportStar(require("./common-methods"), exports);
19
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["utilities/shared/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,+CAA6B","sourcesContent":["export * from './currency';\nexport * from './nutritions';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["utilities/shared/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,+CAA6B;AAC7B,mDAAiC","sourcesContent":["export * from './currency';\nexport * from './nutritions';\nexport * from './common-methods';\n"]}
@@ -1,2 +1,3 @@
1
1
  export * from './currency';
2
2
  export * from './nutritions';
3
+ export * from './common-methods';
@@ -16,4 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./currency"), exports);
18
18
  __exportStar(require("./nutritions"), exports);
19
+ __exportStar(require("./common-methods"), exports);
19
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"/","sources":["utilities/shared/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,+CAA6B","sourcesContent":["export * from './currency';\nexport * from './nutritions';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"/","sources":["utilities/shared/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6CAA2B;AAC3B,+CAA6B;AAC7B,mDAAiC","sourcesContent":["export * from './currency';\nexport * from './nutritions';\nexport * from './common-methods';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lyxa.ai/core",
3
- "version": "1.2.25",
3
+ "version": "1.2.27",
4
4
  "description": "The Core system of the Lyxa services.",
5
5
  "author": "elie <42282499+Internalizable@users.noreply.github.com>",
6
6
  "license": "MIT",