@ingissa/navcore-mapbox 1.0.4 → 1.0.9
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/LICENSE +3 -0
- package/dist/index.d.mts +37 -18
- package/dist/index.d.ts +37 -18
- package/dist/index.js +5 -30
- package/dist/index.mjs +5 -30
- package/package.json +10 -15
package/LICENSE
ADDED
package/dist/index.d.mts
CHANGED
|
@@ -1,40 +1,60 @@
|
|
|
1
|
-
import { DirectionsOptions, DirectionsProvider, Coordinate, DirectionsResult } from '@ingissa/navcore-core';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* MapboxDirectionsProvider
|
|
5
3
|
*
|
|
6
4
|
* Implements DirectionsProvider using the Mapbox Directions API.
|
|
7
5
|
* Handles waypoint chunking internally for routes with >25 waypoints.
|
|
8
6
|
*/
|
|
9
|
-
|
|
10
|
-
type MapboxProfile = 'driving' | 'driving-traffic' | 'cycling' | 'walking';
|
|
7
|
+
type Coordinate = [number, number];
|
|
11
8
|
interface MapboxDirectionsConfig {
|
|
12
9
|
/** Mapbox access token */
|
|
13
10
|
accessToken: string;
|
|
14
11
|
/** Routing profile (default: 'driving') */
|
|
15
|
-
profile?:
|
|
12
|
+
profile?: 'driving' | 'driving-traffic' | 'cycling' | 'walking';
|
|
16
13
|
/** API base URL (default: Mapbox production) */
|
|
17
14
|
baseUrl?: string;
|
|
18
15
|
/** Max waypoints per API call (default: 25, Mapbox limit) */
|
|
19
16
|
maxWaypointsPerChunk?: number;
|
|
20
|
-
/** Optional fetch implementation for tests, React Native, or custom runtimes */
|
|
21
|
-
fetchFn?: typeof fetch;
|
|
22
|
-
/** Request timeout in milliseconds. Set to 0 to disable. */
|
|
23
|
-
timeoutMs?: number;
|
|
24
17
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
interface RouteResult {
|
|
19
|
+
geometry: Coordinate[];
|
|
20
|
+
distance: number;
|
|
21
|
+
duration: number;
|
|
22
|
+
legs: Array<{
|
|
23
|
+
distance: number;
|
|
24
|
+
duration: number;
|
|
25
|
+
steps?: Array<{
|
|
26
|
+
distance: number;
|
|
27
|
+
duration: number;
|
|
28
|
+
geometry: Coordinate[];
|
|
29
|
+
maneuver: {
|
|
30
|
+
type: string;
|
|
31
|
+
modifier?: string;
|
|
32
|
+
location: Coordinate;
|
|
33
|
+
bearing_before: number;
|
|
34
|
+
bearing_after: number;
|
|
35
|
+
instruction?: string;
|
|
36
|
+
};
|
|
37
|
+
name?: string;
|
|
38
|
+
}>;
|
|
39
|
+
}>;
|
|
40
|
+
raw?: unknown;
|
|
41
|
+
}
|
|
42
|
+
interface RouteOptions {
|
|
43
|
+
profile?: string;
|
|
44
|
+
alternatives?: boolean;
|
|
45
|
+
steps?: boolean;
|
|
46
|
+
geometries?: string;
|
|
47
|
+
overview?: string;
|
|
48
|
+
language?: string;
|
|
49
|
+
}
|
|
50
|
+
declare class MapboxDirectionsProvider {
|
|
31
51
|
private readonly config;
|
|
32
52
|
constructor(config: MapboxDirectionsConfig);
|
|
33
53
|
/**
|
|
34
54
|
* Get a route through the given waypoints.
|
|
35
55
|
* Automatically chunks if waypoints exceed the Mapbox limit.
|
|
36
56
|
*/
|
|
37
|
-
getRoute(waypoints: Coordinate[], options?:
|
|
57
|
+
getRoute(waypoints: Coordinate[], options?: RouteOptions): Promise<RouteResult>;
|
|
38
58
|
/**
|
|
39
59
|
* Fetch a single route segment from the Mapbox API.
|
|
40
60
|
*/
|
|
@@ -43,7 +63,6 @@ declare class MapboxDirectionsProvider implements DirectionsProvider {
|
|
|
43
63
|
* Fetch multi-segment route, stitching chunks with OVERLAP_1 strategy.
|
|
44
64
|
*/
|
|
45
65
|
private fetchChunkedRoute;
|
|
46
|
-
private fetchWithTimeout;
|
|
47
66
|
}
|
|
48
67
|
|
|
49
|
-
export { type MapboxDirectionsConfig,
|
|
68
|
+
export { type MapboxDirectionsConfig, MapboxDirectionsProvider };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,40 +1,60 @@
|
|
|
1
|
-
import { DirectionsOptions, DirectionsProvider, Coordinate, DirectionsResult } from '@ingissa/navcore-core';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* MapboxDirectionsProvider
|
|
5
3
|
*
|
|
6
4
|
* Implements DirectionsProvider using the Mapbox Directions API.
|
|
7
5
|
* Handles waypoint chunking internally for routes with >25 waypoints.
|
|
8
6
|
*/
|
|
9
|
-
|
|
10
|
-
type MapboxProfile = 'driving' | 'driving-traffic' | 'cycling' | 'walking';
|
|
7
|
+
type Coordinate = [number, number];
|
|
11
8
|
interface MapboxDirectionsConfig {
|
|
12
9
|
/** Mapbox access token */
|
|
13
10
|
accessToken: string;
|
|
14
11
|
/** Routing profile (default: 'driving') */
|
|
15
|
-
profile?:
|
|
12
|
+
profile?: 'driving' | 'driving-traffic' | 'cycling' | 'walking';
|
|
16
13
|
/** API base URL (default: Mapbox production) */
|
|
17
14
|
baseUrl?: string;
|
|
18
15
|
/** Max waypoints per API call (default: 25, Mapbox limit) */
|
|
19
16
|
maxWaypointsPerChunk?: number;
|
|
20
|
-
/** Optional fetch implementation for tests, React Native, or custom runtimes */
|
|
21
|
-
fetchFn?: typeof fetch;
|
|
22
|
-
/** Request timeout in milliseconds. Set to 0 to disable. */
|
|
23
|
-
timeoutMs?: number;
|
|
24
17
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
18
|
+
interface RouteResult {
|
|
19
|
+
geometry: Coordinate[];
|
|
20
|
+
distance: number;
|
|
21
|
+
duration: number;
|
|
22
|
+
legs: Array<{
|
|
23
|
+
distance: number;
|
|
24
|
+
duration: number;
|
|
25
|
+
steps?: Array<{
|
|
26
|
+
distance: number;
|
|
27
|
+
duration: number;
|
|
28
|
+
geometry: Coordinate[];
|
|
29
|
+
maneuver: {
|
|
30
|
+
type: string;
|
|
31
|
+
modifier?: string;
|
|
32
|
+
location: Coordinate;
|
|
33
|
+
bearing_before: number;
|
|
34
|
+
bearing_after: number;
|
|
35
|
+
instruction?: string;
|
|
36
|
+
};
|
|
37
|
+
name?: string;
|
|
38
|
+
}>;
|
|
39
|
+
}>;
|
|
40
|
+
raw?: unknown;
|
|
41
|
+
}
|
|
42
|
+
interface RouteOptions {
|
|
43
|
+
profile?: string;
|
|
44
|
+
alternatives?: boolean;
|
|
45
|
+
steps?: boolean;
|
|
46
|
+
geometries?: string;
|
|
47
|
+
overview?: string;
|
|
48
|
+
language?: string;
|
|
49
|
+
}
|
|
50
|
+
declare class MapboxDirectionsProvider {
|
|
31
51
|
private readonly config;
|
|
32
52
|
constructor(config: MapboxDirectionsConfig);
|
|
33
53
|
/**
|
|
34
54
|
* Get a route through the given waypoints.
|
|
35
55
|
* Automatically chunks if waypoints exceed the Mapbox limit.
|
|
36
56
|
*/
|
|
37
|
-
getRoute(waypoints: Coordinate[], options?:
|
|
57
|
+
getRoute(waypoints: Coordinate[], options?: RouteOptions): Promise<RouteResult>;
|
|
38
58
|
/**
|
|
39
59
|
* Fetch a single route segment from the Mapbox API.
|
|
40
60
|
*/
|
|
@@ -43,7 +63,6 @@ declare class MapboxDirectionsProvider implements DirectionsProvider {
|
|
|
43
63
|
* Fetch multi-segment route, stitching chunks with OVERLAP_1 strategy.
|
|
44
64
|
*/
|
|
45
65
|
private fetchChunkedRoute;
|
|
46
|
-
private fetchWithTimeout;
|
|
47
66
|
}
|
|
48
67
|
|
|
49
|
-
export { type MapboxDirectionsConfig,
|
|
68
|
+
export { type MapboxDirectionsConfig, MapboxDirectionsProvider };
|
package/dist/index.js
CHANGED
|
@@ -3,20 +3,13 @@
|
|
|
3
3
|
// src/MapboxDirectionsProvider.ts
|
|
4
4
|
var DEFAULT_BASE_URL = "https://api.mapbox.com/directions/v5/mapbox";
|
|
5
5
|
var MAX_WAYPOINTS = 25;
|
|
6
|
-
var DEFAULT_TIMEOUT_MS = 15e3;
|
|
7
6
|
var MapboxDirectionsProvider = class {
|
|
8
7
|
constructor(config) {
|
|
9
|
-
const fetchFn = config.fetchFn ?? globalThis.fetch?.bind(globalThis);
|
|
10
|
-
if (!fetchFn) {
|
|
11
|
-
throw new Error("[Mapbox] fetch is not available. Pass config.fetchFn in this runtime.");
|
|
12
|
-
}
|
|
13
8
|
this.config = {
|
|
14
9
|
accessToken: config.accessToken,
|
|
15
10
|
profile: config.profile ?? "driving",
|
|
16
11
|
baseUrl: config.baseUrl ?? DEFAULT_BASE_URL,
|
|
17
|
-
maxWaypointsPerChunk: config.maxWaypointsPerChunk ?? MAX_WAYPOINTS
|
|
18
|
-
fetchFn,
|
|
19
|
-
timeoutMs: config.timeoutMs ?? DEFAULT_TIMEOUT_MS
|
|
12
|
+
maxWaypointsPerChunk: config.maxWaypointsPerChunk ?? MAX_WAYPOINTS
|
|
20
13
|
};
|
|
21
14
|
}
|
|
22
15
|
/**
|
|
@@ -49,10 +42,9 @@ var MapboxDirectionsProvider = class {
|
|
|
49
42
|
params.set("language", options.language);
|
|
50
43
|
}
|
|
51
44
|
const url = `${this.config.baseUrl}/${profile}/${coords}?${params}`;
|
|
52
|
-
const response = await
|
|
45
|
+
const response = await fetch(url);
|
|
53
46
|
if (!response.ok) {
|
|
54
|
-
|
|
55
|
-
throw new Error(`[Mapbox] HTTP ${response.status}: ${text || response.statusText}`);
|
|
47
|
+
throw new Error(`Mapbox API error: ${response.status} ${response.statusText}`);
|
|
56
48
|
}
|
|
57
49
|
const data = await response.json();
|
|
58
50
|
if (!data.routes || data.routes.length === 0) {
|
|
@@ -74,8 +66,8 @@ var MapboxDirectionsProvider = class {
|
|
|
74
66
|
type: step.maneuver?.type ?? "unknown",
|
|
75
67
|
modifier: step.maneuver?.modifier,
|
|
76
68
|
location: step.maneuver?.location ?? [0, 0],
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
bearing_before: step.maneuver?.bearing_before ?? 0,
|
|
70
|
+
bearing_after: step.maneuver?.bearing_after ?? 0,
|
|
79
71
|
instruction: step.maneuver?.instruction
|
|
80
72
|
},
|
|
81
73
|
name: step.name
|
|
@@ -124,23 +116,6 @@ var MapboxDirectionsProvider = class {
|
|
|
124
116
|
raw: results.map((r) => r.raw)
|
|
125
117
|
};
|
|
126
118
|
}
|
|
127
|
-
async fetchWithTimeout(url, init) {
|
|
128
|
-
if (this.config.timeoutMs <= 0 || typeof AbortController === "undefined") {
|
|
129
|
-
return this.config.fetchFn(url, init);
|
|
130
|
-
}
|
|
131
|
-
const controller = new AbortController();
|
|
132
|
-
const timeout = setTimeout(() => controller.abort(), this.config.timeoutMs);
|
|
133
|
-
try {
|
|
134
|
-
return await this.config.fetchFn(url, { ...init, signal: controller.signal });
|
|
135
|
-
} catch (error) {
|
|
136
|
-
if (error.name === "AbortError") {
|
|
137
|
-
throw new Error(`[Mapbox] Request timed out after ${this.config.timeoutMs}ms`);
|
|
138
|
-
}
|
|
139
|
-
throw error;
|
|
140
|
-
} finally {
|
|
141
|
-
clearTimeout(timeout);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
119
|
};
|
|
145
120
|
|
|
146
121
|
exports.MapboxDirectionsProvider = MapboxDirectionsProvider;
|
package/dist/index.mjs
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
// src/MapboxDirectionsProvider.ts
|
|
2
2
|
var DEFAULT_BASE_URL = "https://api.mapbox.com/directions/v5/mapbox";
|
|
3
3
|
var MAX_WAYPOINTS = 25;
|
|
4
|
-
var DEFAULT_TIMEOUT_MS = 15e3;
|
|
5
4
|
var MapboxDirectionsProvider = class {
|
|
6
5
|
constructor(config) {
|
|
7
|
-
const fetchFn = config.fetchFn ?? globalThis.fetch?.bind(globalThis);
|
|
8
|
-
if (!fetchFn) {
|
|
9
|
-
throw new Error("[Mapbox] fetch is not available. Pass config.fetchFn in this runtime.");
|
|
10
|
-
}
|
|
11
6
|
this.config = {
|
|
12
7
|
accessToken: config.accessToken,
|
|
13
8
|
profile: config.profile ?? "driving",
|
|
14
9
|
baseUrl: config.baseUrl ?? DEFAULT_BASE_URL,
|
|
15
|
-
maxWaypointsPerChunk: config.maxWaypointsPerChunk ?? MAX_WAYPOINTS
|
|
16
|
-
fetchFn,
|
|
17
|
-
timeoutMs: config.timeoutMs ?? DEFAULT_TIMEOUT_MS
|
|
10
|
+
maxWaypointsPerChunk: config.maxWaypointsPerChunk ?? MAX_WAYPOINTS
|
|
18
11
|
};
|
|
19
12
|
}
|
|
20
13
|
/**
|
|
@@ -47,10 +40,9 @@ var MapboxDirectionsProvider = class {
|
|
|
47
40
|
params.set("language", options.language);
|
|
48
41
|
}
|
|
49
42
|
const url = `${this.config.baseUrl}/${profile}/${coords}?${params}`;
|
|
50
|
-
const response = await
|
|
43
|
+
const response = await fetch(url);
|
|
51
44
|
if (!response.ok) {
|
|
52
|
-
|
|
53
|
-
throw new Error(`[Mapbox] HTTP ${response.status}: ${text || response.statusText}`);
|
|
45
|
+
throw new Error(`Mapbox API error: ${response.status} ${response.statusText}`);
|
|
54
46
|
}
|
|
55
47
|
const data = await response.json();
|
|
56
48
|
if (!data.routes || data.routes.length === 0) {
|
|
@@ -72,8 +64,8 @@ var MapboxDirectionsProvider = class {
|
|
|
72
64
|
type: step.maneuver?.type ?? "unknown",
|
|
73
65
|
modifier: step.maneuver?.modifier,
|
|
74
66
|
location: step.maneuver?.location ?? [0, 0],
|
|
75
|
-
|
|
76
|
-
|
|
67
|
+
bearing_before: step.maneuver?.bearing_before ?? 0,
|
|
68
|
+
bearing_after: step.maneuver?.bearing_after ?? 0,
|
|
77
69
|
instruction: step.maneuver?.instruction
|
|
78
70
|
},
|
|
79
71
|
name: step.name
|
|
@@ -122,23 +114,6 @@ var MapboxDirectionsProvider = class {
|
|
|
122
114
|
raw: results.map((r) => r.raw)
|
|
123
115
|
};
|
|
124
116
|
}
|
|
125
|
-
async fetchWithTimeout(url, init) {
|
|
126
|
-
if (this.config.timeoutMs <= 0 || typeof AbortController === "undefined") {
|
|
127
|
-
return this.config.fetchFn(url, init);
|
|
128
|
-
}
|
|
129
|
-
const controller = new AbortController();
|
|
130
|
-
const timeout = setTimeout(() => controller.abort(), this.config.timeoutMs);
|
|
131
|
-
try {
|
|
132
|
-
return await this.config.fetchFn(url, { ...init, signal: controller.signal });
|
|
133
|
-
} catch (error) {
|
|
134
|
-
if (error.name === "AbortError") {
|
|
135
|
-
throw new Error(`[Mapbox] Request timed out after ${this.config.timeoutMs}ms`);
|
|
136
|
-
}
|
|
137
|
-
throw error;
|
|
138
|
-
} finally {
|
|
139
|
-
clearTimeout(timeout);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
117
|
};
|
|
143
118
|
|
|
144
119
|
export { MapboxDirectionsProvider };
|
package/package.json
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ingissa/navcore-mapbox",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Mapbox GL adapter for NavCore
|
|
3
|
+
"version": "1.0.9",
|
|
4
|
+
"description": "Mapbox GL adapter for NavCore — renderer and directions provider.",
|
|
5
5
|
"author": "Ingissa <8abnav@gmail.com>",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
7
7
|
"homepage": "https://navcore-web.vercel.app/",
|
|
8
|
-
"repository": {
|
|
9
|
-
"type": "git",
|
|
10
|
-
"url": "git+https://github.com/ingissa/ingissa-navcore-examples.git"
|
|
11
|
-
},
|
|
12
|
-
"bugs": {
|
|
13
|
-
"url": "https://github.com/ingissa/ingissa-navcore-examples/issues"
|
|
14
|
-
},
|
|
15
8
|
"main": "dist/index.js",
|
|
16
9
|
"module": "dist/index.mjs",
|
|
17
10
|
"types": "dist/index.d.ts",
|
|
@@ -23,27 +16,29 @@
|
|
|
23
16
|
}
|
|
24
17
|
},
|
|
25
18
|
"files": [
|
|
26
|
-
"dist"
|
|
19
|
+
"dist",
|
|
20
|
+
"LICENSE"
|
|
27
21
|
],
|
|
28
22
|
"sideEffects": false,
|
|
29
23
|
"publishConfig": {
|
|
30
24
|
"access": "public"
|
|
31
25
|
},
|
|
32
26
|
"engines": {
|
|
33
|
-
"node": ">=
|
|
27
|
+
"node": ">=16"
|
|
34
28
|
},
|
|
35
29
|
"scripts": {
|
|
36
30
|
"build": "tsup",
|
|
37
31
|
"lint": "tsc --noEmit",
|
|
38
|
-
"prepublishOnly": "npm run build"
|
|
32
|
+
"prepublishOnly": "npm run build --prefix ../.. && node ../../scripts/check-release.mjs"
|
|
39
33
|
},
|
|
40
34
|
"peerDependencies": {
|
|
41
|
-
"@ingissa/navcore-core": "^1.0.
|
|
35
|
+
"@ingissa/navcore-core": "^1.0.9",
|
|
42
36
|
"@rnmapbox/maps": ">=10.0.0"
|
|
43
37
|
},
|
|
44
38
|
"peerDependenciesMeta": {
|
|
45
39
|
"@rnmapbox/maps": {
|
|
46
40
|
"optional": true
|
|
47
41
|
}
|
|
48
|
-
}
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {}
|
|
49
44
|
}
|