@wemap/routers 13.0.0 → 13.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -2348,6 +2348,25 @@ const ColorUtils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
2348
2348
  __proto__: null,
2349
2349
  getQualitativeColor
2350
2350
  }, Symbol.toStringTag, { value: "Module" }));
2351
+ function formatSO(value, ...xargs) {
2352
+ let str = value.toString();
2353
+ if (xargs.length) {
2354
+ const t = typeof xargs[0];
2355
+ const args = t === "string" || t === "number" ? xargs.slice() : xargs[0];
2356
+ for (const key in args) {
2357
+ str = str.replace(new RegExp("\\{" + key + "\\}", "gi"), args[key]);
2358
+ }
2359
+ }
2360
+ return str;
2361
+ }
2362
+ function toUpperCase(str) {
2363
+ return str.toUpperCase();
2364
+ }
2365
+ const StringUtils = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2366
+ __proto__: null,
2367
+ formatSO,
2368
+ toUpperCase
2369
+ }, Symbol.toStringTag, { value: "Module" }));
2351
2370
  const SPEEDS = {
2352
2371
  DEFAULT: 4,
2353
2372
  WHEELCHAIR: 3
@@ -4514,6 +4533,101 @@ class WemapMultiRemoteRouter extends RemoteRouter {
4514
4533
  }
4515
4534
  }
4516
4535
  const WemapMultiRemoteRouter$1 = new WemapMultiRemoteRouter();
4536
+ class TictactripRemoteRouter extends RemoteRouter {
4537
+ /**
4538
+ * @override
4539
+ */
4540
+ get rname() {
4541
+ return "tictactrip";
4542
+ }
4543
+ async getItineraries(endpointUrl, routerRequest) {
4544
+ const bodyParams = this.getBodyParams(routerRequest);
4545
+ const url = new URL(endpointUrl);
4546
+ const res = await fetch(url, {
4547
+ method: "POST",
4548
+ headers: {
4549
+ "Content-Type": "application/json"
4550
+ },
4551
+ body: JSON.stringify(bodyParams)
4552
+ }).catch(() => {
4553
+ throw RemoteRoutingError.unreachableServer(this.rname, url.toString());
4554
+ });
4555
+ const jsonResponse = await res.json().catch(() => {
4556
+ throw RemoteRoutingError.responseNotParsing(this.rname, url.toString());
4557
+ });
4558
+ const itineraries = this.parseResponse(jsonResponse);
4559
+ return itineraries;
4560
+ }
4561
+ getBodyParams(routerRequest) {
4562
+ const { origin, destination } = routerRequest;
4563
+ return {
4564
+ origin: {
4565
+ latitude: origin.lat,
4566
+ longitude: origin.lng
4567
+ },
4568
+ destination: {
4569
+ latitude: destination.lat,
4570
+ longitude: destination.lng
4571
+ },
4572
+ outbound_date: (/* @__PURE__ */ new Date()).toISOString(),
4573
+ passengers: [{ age: 30 }]
4574
+ };
4575
+ }
4576
+ parseResponse(json) {
4577
+ if (!json || !json.trips)
4578
+ return [];
4579
+ return Object.values(json.trips).map((trip) => {
4580
+ const legs = trip.segments.map((segment) => {
4581
+ const transitMode = StringUtils.toUpperCase(segment.transportType);
4582
+ const startSection = new Coordinates(segment.origin.latitude, segment.origin.longitude);
4583
+ const endSection = new Coordinates(segment.destination.latitude, segment.destination.longitude);
4584
+ const legCoords = [startSection, endSection];
4585
+ const stepsBuilder = new StepsBuilder().setStart(startSection).setEnd(endSection).setPathCoords(legCoords);
4586
+ stepsBuilder.setStepsInfo([{
4587
+ coords: startSection,
4588
+ type: "depart",
4589
+ direction: null
4590
+ }, {
4591
+ coords: endSection,
4592
+ type: "arrive",
4593
+ direction: null
4594
+ }]);
4595
+ return new Leg({
4596
+ start: {
4597
+ name: segment.origin.name,
4598
+ coords: startSection
4599
+ },
4600
+ end: {
4601
+ name: segment.destination.name,
4602
+ coords: endSection
4603
+ },
4604
+ coords: [
4605
+ startSection,
4606
+ endSection
4607
+ ],
4608
+ transitMode,
4609
+ duration: segment.durationMinutes * 60,
4610
+ startTime: new Date(segment.departureLocalISO).getTime(),
4611
+ endTime: new Date(segment.arrivalLocalISO).getTime(),
4612
+ transportInfo: {
4613
+ name: segment.provider.name,
4614
+ price: segment.priceCents / 100
4615
+ },
4616
+ steps: stepsBuilder.build()
4617
+ });
4618
+ });
4619
+ return new Itinerary({
4620
+ origin: new Coordinates(trip.origin.latitude, trip.origin.longitude),
4621
+ destination: new Coordinates(trip.destination.latitude, trip.destination.longitude),
4622
+ duration: trip.durationMinutes * 60,
4623
+ startTime: new Date(trip.departureLocalISO).getTime(),
4624
+ endTime: new Date(trip.arrivalLocalISO).getTime(),
4625
+ legs
4626
+ });
4627
+ });
4628
+ }
4629
+ }
4630
+ const TictactripRemoteRouter$1 = new TictactripRemoteRouter();
4517
4631
  const remoteRouters = [
4518
4632
  CitywayRemoteRouter$1,
4519
4633
  NavitiaRemoteRouter$1,
@@ -4521,6 +4635,7 @@ const remoteRouters = [
4521
4635
  IdfmRemoteRouter$1,
4522
4636
  OsrmRemoteRouter$1,
4523
4637
  OtpRemoteRouter$1,
4638
+ TictactripRemoteRouter$1,
4524
4639
  WemapMultiRemoteRouter$1
4525
4640
  ];
4526
4641
  class RemoteRouterManager {
@@ -13973,6 +14088,7 @@ export {
13973
14088
  RemoteRoutingError,
13974
14089
  RoutingError,
13975
14090
  StatusCode,
14091
+ TictactripRemoteRouter$1 as TictactripRemoteRouter,
13976
14092
  Vertex,
13977
14093
  WemapMultiRemoteRouter$1 as WemapMultiRemoteRouter,
13978
14094
  WemapMultiRouter,