@cloudparse/up-miniapps-sdk 0.1.6 → 0.2.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/README.md +167 -2
- package/dist/chunk-S4UHRBSM.js +252 -0
- package/dist/chunk-S4UHRBSM.js.map +1 -0
- package/dist/host/index.d.cts +2 -0
- package/dist/host/index.d.ts +2 -0
- package/dist/host.cjs +279 -0
- package/dist/host.cjs.map +1 -0
- package/dist/host.js +11 -0
- package/dist/host.js.map +1 -0
- package/dist/index-B9dDciJq.d.cts +65 -0
- package/dist/index-B9dDciJq.d.ts +65 -0
- package/dist/index.browser.min.js +879 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/index.cjs +3628 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.css +2 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.cts +1144 -0
- package/dist/index.d.ts +768 -152
- package/dist/index.js +3020 -57
- package/dist/index.js.map +1 -1
- package/dist/style.css +2279 -0
- package/package.json +55 -13
- package/dist/index.d.mts +0 -528
- package/dist/index.mjs +0 -348
- package/dist/index.mjs.map +0 -1
package/dist/host.cjs
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/host/index.ts
|
|
21
|
+
var host_exports = {};
|
|
22
|
+
__export(host_exports, {
|
|
23
|
+
handleClearRoute: () => handleClearRoute,
|
|
24
|
+
handleDrawRoute: () => handleDrawRoute,
|
|
25
|
+
handleRouteRequest: () => handleRouteRequest
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(host_exports);
|
|
28
|
+
|
|
29
|
+
// src/services/routingService.ts
|
|
30
|
+
var RoutingService = {
|
|
31
|
+
createErrorResponse(req, code, message) {
|
|
32
|
+
return {
|
|
33
|
+
error: { code, message },
|
|
34
|
+
requestId: req.requestId,
|
|
35
|
+
sdkVersion: req.sdkVersion,
|
|
36
|
+
success: false,
|
|
37
|
+
type: "SDK_ROUTING_GETROUTE_RESPONSE"
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
decodePolyline(str, precision) {
|
|
41
|
+
let index = 0, lat = 0, lng = 0;
|
|
42
|
+
const coordinates = [];
|
|
43
|
+
const shift = 10 ** precision;
|
|
44
|
+
while (index < str.length) {
|
|
45
|
+
let b, shiftNum = 0, result = 0;
|
|
46
|
+
do {
|
|
47
|
+
b = str.charCodeAt(index++) - 63;
|
|
48
|
+
result |= (b & 31) << shiftNum;
|
|
49
|
+
shiftNum += 5;
|
|
50
|
+
} while (b >= 32);
|
|
51
|
+
const dlat = result & 1 ? ~(result >> 1) : result >> 1;
|
|
52
|
+
lat += dlat;
|
|
53
|
+
shiftNum = 0;
|
|
54
|
+
result = 0;
|
|
55
|
+
do {
|
|
56
|
+
b = str.charCodeAt(index++) - 63;
|
|
57
|
+
result |= (b & 31) << shiftNum;
|
|
58
|
+
shiftNum += 5;
|
|
59
|
+
} while (b >= 32);
|
|
60
|
+
const dlng = result & 1 ? ~(result >> 1) : result >> 1;
|
|
61
|
+
lng += dlng;
|
|
62
|
+
coordinates.push([lng / shift, lat / shift]);
|
|
63
|
+
}
|
|
64
|
+
return coordinates;
|
|
65
|
+
},
|
|
66
|
+
async fetchOSRMRoute(req, coords, profile, baseUrl) {
|
|
67
|
+
const coordsString = coords.map((c) => `${c[0]},${c[1]}`).join(";");
|
|
68
|
+
const osrmProfile = profile === "walking" ? "foot" : profile === "driving" ? "car" : "bike";
|
|
69
|
+
const url = `${baseUrl}/route/v1/${osrmProfile}/${coordsString}?overview=full&geometries=geojson&steps=true`;
|
|
70
|
+
const response = await fetch(url);
|
|
71
|
+
if (!response.ok) {
|
|
72
|
+
throw new Error(`OSRM Error: ${response.statusText}`);
|
|
73
|
+
}
|
|
74
|
+
const data = await response.json();
|
|
75
|
+
if (data.code !== "Ok" || !data.routes || data.routes.length === 0) {
|
|
76
|
+
throw new Error("NO_ROUTE");
|
|
77
|
+
}
|
|
78
|
+
const route = data.routes[0];
|
|
79
|
+
const steps = route.legs?.flatMap(
|
|
80
|
+
(leg) => leg.steps?.map((step) => ({
|
|
81
|
+
distance: step.distance,
|
|
82
|
+
duration: step.duration,
|
|
83
|
+
instruction: step.maneuver?.instruction || "Continue"
|
|
84
|
+
}))
|
|
85
|
+
) || [];
|
|
86
|
+
return {
|
|
87
|
+
data: {
|
|
88
|
+
distanceMeters: route.distance,
|
|
89
|
+
durationSeconds: route.duration,
|
|
90
|
+
geometry: route.geometry,
|
|
91
|
+
steps
|
|
92
|
+
},
|
|
93
|
+
requestId: req.requestId,
|
|
94
|
+
sdkVersion: req.sdkVersion,
|
|
95
|
+
success: true,
|
|
96
|
+
type: "SDK_ROUTING_GETROUTE_RESPONSE"
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
async fetchRoute(req, config) {
|
|
100
|
+
const { origin, destination, waypoints, profile, language } = req.payload;
|
|
101
|
+
if (!this.isValidCoordinate(origin) || !this.isValidCoordinate(destination)) {
|
|
102
|
+
return this.createErrorResponse(
|
|
103
|
+
req,
|
|
104
|
+
"INVALID_INPUT",
|
|
105
|
+
"Origin or destination coordinates are invalid."
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
if (waypoints && !waypoints.every(this.isValidCoordinate)) {
|
|
109
|
+
return this.createErrorResponse(
|
|
110
|
+
req,
|
|
111
|
+
"INVALID_INPUT",
|
|
112
|
+
"One or more waypoints are invalid."
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
const allCoords = [origin, ...waypoints || [], destination];
|
|
116
|
+
try {
|
|
117
|
+
if (config.backend === "osrm") {
|
|
118
|
+
return await this.fetchOSRMRoute(
|
|
119
|
+
req,
|
|
120
|
+
allCoords,
|
|
121
|
+
profile,
|
|
122
|
+
config.baseUrl
|
|
123
|
+
);
|
|
124
|
+
} else {
|
|
125
|
+
return await this.fetchValhallaRoute(
|
|
126
|
+
req,
|
|
127
|
+
allCoords,
|
|
128
|
+
profile,
|
|
129
|
+
language,
|
|
130
|
+
config.baseUrl
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
} catch (error) {
|
|
134
|
+
if (error instanceof Error && error.message.includes("NO_ROUTE")) {
|
|
135
|
+
return this.createErrorResponse(
|
|
136
|
+
req,
|
|
137
|
+
"NO_ROUTE",
|
|
138
|
+
"No route could be found for the given points."
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
if (error instanceof TypeError) {
|
|
142
|
+
return this.createErrorResponse(
|
|
143
|
+
req,
|
|
144
|
+
"NETWORK_ERROR",
|
|
145
|
+
"Failed to connect to the routing backend."
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
return this.createErrorResponse(
|
|
149
|
+
req,
|
|
150
|
+
"BACKEND_ERROR",
|
|
151
|
+
`Routing backend error: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
async fetchValhallaRoute(req, coords, profile, language, baseUrl) {
|
|
156
|
+
const valhallaProfile = profile === "driving" ? "auto" : profile === "walking" ? "pedestrian" : "bicycle";
|
|
157
|
+
const body = {
|
|
158
|
+
costing: valhallaProfile,
|
|
159
|
+
directions_options: {
|
|
160
|
+
language: language || "en-US"
|
|
161
|
+
},
|
|
162
|
+
locations: coords.map((c) => ({ lat: c[1], lon: c[0] }))
|
|
163
|
+
};
|
|
164
|
+
const response = await fetch(`${baseUrl}/route`, {
|
|
165
|
+
body: JSON.stringify(body),
|
|
166
|
+
headers: { "Content-Type": "application/json" },
|
|
167
|
+
method: "POST"
|
|
168
|
+
});
|
|
169
|
+
if (!response.ok) {
|
|
170
|
+
throw new Error(`Valhalla Error: ${response.statusText}`);
|
|
171
|
+
}
|
|
172
|
+
const data = await response.json();
|
|
173
|
+
if (!data.trip || !data.trip.legs || data.trip.legs.length === 0) {
|
|
174
|
+
throw new Error("NO_ROUTE");
|
|
175
|
+
}
|
|
176
|
+
const trip = data.trip;
|
|
177
|
+
const decodedCoordinates = this.decodePolyline(trip.legs[0].shape, 6);
|
|
178
|
+
const steps = trip.legs.flatMap(
|
|
179
|
+
(leg) => leg.maneuvers?.map((maneuver) => ({
|
|
180
|
+
distance: maneuver.length * 1e3,
|
|
181
|
+
// Valhalla returns km
|
|
182
|
+
duration: maneuver.time,
|
|
183
|
+
instruction: maneuver.instruction || "Continue"
|
|
184
|
+
}))
|
|
185
|
+
) || [];
|
|
186
|
+
return {
|
|
187
|
+
data: {
|
|
188
|
+
distanceMeters: trip.summary.length * 1e3,
|
|
189
|
+
// km to m
|
|
190
|
+
durationSeconds: trip.summary.time,
|
|
191
|
+
geometry: {
|
|
192
|
+
coordinates: decodedCoordinates,
|
|
193
|
+
type: "LineString"
|
|
194
|
+
},
|
|
195
|
+
steps
|
|
196
|
+
},
|
|
197
|
+
requestId: req.requestId,
|
|
198
|
+
sdkVersion: req.sdkVersion,
|
|
199
|
+
success: true,
|
|
200
|
+
type: "SDK_ROUTING_GETROUTE_RESPONSE"
|
|
201
|
+
};
|
|
202
|
+
},
|
|
203
|
+
isValidCoordinate(coord) {
|
|
204
|
+
const [lng, lat] = coord;
|
|
205
|
+
return lng >= -180 && lng <= 180 && lat >= -90 && lat <= 90;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// src/host/routingHandler.ts
|
|
210
|
+
async function handleRouteRequest(req, config) {
|
|
211
|
+
return RoutingService.fetchRoute(req, config);
|
|
212
|
+
}
|
|
213
|
+
function handleDrawRoute(map, miniAppId, req) {
|
|
214
|
+
const sourceId = `sdk-route-${miniAppId}`;
|
|
215
|
+
const casingLayerId = `sdk-route-casing-${miniAppId}`;
|
|
216
|
+
const lineLayerId = `sdk-route-line-${miniAppId}`;
|
|
217
|
+
const geojson = {
|
|
218
|
+
features: [
|
|
219
|
+
{
|
|
220
|
+
geometry: req.payload.routeData.geometry,
|
|
221
|
+
properties: {},
|
|
222
|
+
type: "Feature"
|
|
223
|
+
}
|
|
224
|
+
],
|
|
225
|
+
type: "FeatureCollection"
|
|
226
|
+
};
|
|
227
|
+
const source = map.getSource(sourceId);
|
|
228
|
+
if (source) {
|
|
229
|
+
source.setData(geojson);
|
|
230
|
+
} else {
|
|
231
|
+
map.addSource(sourceId, {
|
|
232
|
+
data: geojson,
|
|
233
|
+
type: "geojson"
|
|
234
|
+
});
|
|
235
|
+
map.addLayer({
|
|
236
|
+
id: casingLayerId,
|
|
237
|
+
layout: {
|
|
238
|
+
"line-cap": "round",
|
|
239
|
+
"line-join": "round"
|
|
240
|
+
},
|
|
241
|
+
paint: {
|
|
242
|
+
"line-color": "#111111",
|
|
243
|
+
"line-opacity": 0.8,
|
|
244
|
+
"line-width": 8
|
|
245
|
+
},
|
|
246
|
+
source: sourceId,
|
|
247
|
+
type: "line"
|
|
248
|
+
});
|
|
249
|
+
map.addLayer({
|
|
250
|
+
id: lineLayerId,
|
|
251
|
+
layout: {
|
|
252
|
+
"line-cap": "round",
|
|
253
|
+
"line-join": "round"
|
|
254
|
+
},
|
|
255
|
+
paint: {
|
|
256
|
+
"line-color": "#3b82f6",
|
|
257
|
+
// Bright blue
|
|
258
|
+
"line-width": 4
|
|
259
|
+
},
|
|
260
|
+
source: sourceId,
|
|
261
|
+
type: "line"
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
function handleClearRoute(map, miniAppId) {
|
|
266
|
+
const sourceId = `sdk-route-${miniAppId}`;
|
|
267
|
+
const casingLayerId = `sdk-route-casing-${miniAppId}`;
|
|
268
|
+
const lineLayerId = `sdk-route-line-${miniAppId}`;
|
|
269
|
+
if (map.getLayer(lineLayerId)) map.removeLayer(lineLayerId);
|
|
270
|
+
if (map.getLayer(casingLayerId)) map.removeLayer(casingLayerId);
|
|
271
|
+
if (map.getSource(sourceId)) map.removeSource(sourceId);
|
|
272
|
+
}
|
|
273
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
274
|
+
0 && (module.exports = {
|
|
275
|
+
handleClearRoute,
|
|
276
|
+
handleDrawRoute,
|
|
277
|
+
handleRouteRequest
|
|
278
|
+
});
|
|
279
|
+
//# sourceMappingURL=host.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/host/index.ts","../src/services/routingService.ts","../src/host/routingHandler.ts"],"sourcesContent":["export * from \"@miniapps-sdk/host/routingHandler\";\n","import type { RouteRequest, RouteResponse } from \"@miniapps-sdk/types/routing\";\n\nexport interface RoutingBackendConfig {\n backend: \"osrm\" | \"valhalla\";\n baseUrl: string;\n}\n\n/**\n * Core routing service that can be used by both SDK (for direct fetching)\n * and Host (for handling bridge requests).\n */\nexport const RoutingService = {\n createErrorResponse(\n req: RouteRequest,\n code: NonNullable<RouteResponse[\"error\"]>[\"code\"],\n message: string,\n ): RouteResponse {\n return {\n error: { code, message },\n requestId: req.requestId,\n sdkVersion: req.sdkVersion,\n success: false,\n type: \"SDK_ROUTING_GETROUTE_RESPONSE\",\n };\n },\n\n decodePolyline(str: string, precision: number): [number, number][] {\n let index = 0,\n lat = 0,\n lng = 0;\n const coordinates: [number, number][] = [];\n const shift = 10 ** precision;\n\n while (index < str.length) {\n let b: any,\n shiftNum = 0,\n result = 0;\n do {\n b = str.charCodeAt(index++) - 63;\n result |= (b & 0x1f) << shiftNum;\n shiftNum += 5;\n } while (b >= 0x20);\n const dlat = result & 1 ? ~(result >> 1) : result >> 1;\n lat += dlat;\n\n shiftNum = 0;\n result = 0;\n do {\n b = str.charCodeAt(index++) - 63;\n result |= (b & 0x1f) << shiftNum;\n shiftNum += 5;\n } while (b >= 0x20);\n const dlng = result & 1 ? ~(result >> 1) : result >> 1;\n lng += dlng;\n\n coordinates.push([lng / shift, lat / shift]);\n }\n return coordinates;\n },\n\n async fetchOSRMRoute(\n req: RouteRequest,\n coords: [number, number][],\n profile: string,\n baseUrl: string,\n ): Promise<RouteResponse> {\n const coordsString = coords.map((c) => `${c[0]},${c[1]}`).join(\";\");\n const osrmProfile =\n profile === \"walking\" ? \"foot\" : profile === \"driving\" ? \"car\" : \"bike\";\n const url = `${baseUrl}/route/v1/${osrmProfile}/${coordsString}?overview=full&geometries=geojson&steps=true`;\n\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(`OSRM Error: ${response.statusText}`);\n }\n const data = await response.json();\n\n if (data.code !== \"Ok\" || !data.routes || data.routes.length === 0) {\n throw new Error(\"NO_ROUTE\");\n }\n\n const route = data.routes[0];\n const steps =\n route.legs?.flatMap((leg: any) =>\n leg.steps?.map((step: any) => ({\n distance: step.distance,\n duration: step.duration,\n instruction: step.maneuver?.instruction || \"Continue\",\n })),\n ) || [];\n\n return {\n data: {\n distanceMeters: route.distance,\n durationSeconds: route.duration,\n geometry: route.geometry,\n steps,\n },\n requestId: req.requestId,\n sdkVersion: req.sdkVersion,\n success: true,\n type: \"SDK_ROUTING_GETROUTE_RESPONSE\",\n };\n },\n async fetchRoute(\n req: RouteRequest,\n config: RoutingBackendConfig,\n ): Promise<RouteResponse> {\n const { origin, destination, waypoints, profile, language } = req.payload;\n\n if (\n !this.isValidCoordinate(origin) ||\n !this.isValidCoordinate(destination)\n ) {\n return this.createErrorResponse(\n req,\n \"INVALID_INPUT\",\n \"Origin or destination coordinates are invalid.\",\n );\n }\n if (waypoints && !waypoints.every(this.isValidCoordinate)) {\n return this.createErrorResponse(\n req,\n \"INVALID_INPUT\",\n \"One or more waypoints are invalid.\",\n );\n }\n\n const allCoords = [origin, ...(waypoints || []), destination];\n\n try {\n if (config.backend === \"osrm\") {\n return await this.fetchOSRMRoute(\n req,\n allCoords,\n profile,\n config.baseUrl,\n );\n } else {\n return await this.fetchValhallaRoute(\n req,\n allCoords,\n profile,\n language,\n config.baseUrl,\n );\n }\n } catch (error) {\n if (error instanceof Error && error.message.includes(\"NO_ROUTE\")) {\n return this.createErrorResponse(\n req,\n \"NO_ROUTE\",\n \"No route could be found for the given points.\",\n );\n }\n if (error instanceof TypeError) {\n return this.createErrorResponse(\n req,\n \"NETWORK_ERROR\",\n \"Failed to connect to the routing backend.\",\n );\n }\n return this.createErrorResponse(\n req,\n \"BACKEND_ERROR\",\n `Routing backend error: ${error instanceof Error ? error.message : \"Unknown error\"}`,\n );\n }\n },\n\n async fetchValhallaRoute(\n req: RouteRequest,\n coords: [number, number][],\n profile: string,\n language: string | undefined,\n baseUrl: string,\n ): Promise<RouteResponse> {\n const valhallaProfile =\n profile === \"driving\"\n ? \"auto\"\n : profile === \"walking\"\n ? \"pedestrian\"\n : \"bicycle\";\n const body = {\n costing: valhallaProfile,\n directions_options: {\n language: language || \"en-US\",\n },\n locations: coords.map((c) => ({ lat: c[1], lon: c[0] })),\n };\n\n const response = await fetch(`${baseUrl}/route`, {\n body: JSON.stringify(body),\n headers: { \"Content-Type\": \"application/json\" },\n method: \"POST\",\n });\n\n if (!response.ok) {\n throw new Error(`Valhalla Error: ${response.statusText}`);\n }\n const data = await response.json();\n\n if (!data.trip || !data.trip.legs || data.trip.legs.length === 0) {\n throw new Error(\"NO_ROUTE\");\n }\n\n const trip = data.trip;\n const decodedCoordinates = this.decodePolyline(trip.legs[0].shape, 6);\n\n const steps =\n trip.legs.flatMap((leg: any) =>\n leg.maneuvers?.map((maneuver: any) => ({\n distance: maneuver.length * 1000, // Valhalla returns km\n duration: maneuver.time,\n instruction: maneuver.instruction || \"Continue\",\n })),\n ) || [];\n\n return {\n data: {\n distanceMeters: trip.summary.length * 1000, // km to m\n durationSeconds: trip.summary.time,\n geometry: {\n coordinates: decodedCoordinates,\n type: \"LineString\",\n },\n steps,\n },\n requestId: req.requestId,\n sdkVersion: req.sdkVersion,\n success: true,\n type: \"SDK_ROUTING_GETROUTE_RESPONSE\",\n };\n },\n\n isValidCoordinate(coord: [number, number]): boolean {\n const [lng, lat] = coord;\n return lng >= -180 && lng <= 180 && lat >= -90 && lat <= 90;\n },\n};\n","import type { RoutingBackendConfig } from \"@miniapps-sdk/services/routingService\";\nimport { RoutingService } from \"@miniapps-sdk/services/routingService\";\nimport type {\n DrawRouteRequest,\n RouteRequest,\n RouteResponse,\n} from \"@miniapps-sdk/types/routing\";\nimport type { Map } from \"maplibre-gl\";\n\n/**\n * Handles a route request from the mini-app and fetches data from the configured backend.\n */\nexport async function handleRouteRequest(\n req: RouteRequest,\n config: RoutingBackendConfig,\n): Promise<RouteResponse> {\n return RoutingService.fetchRoute(req, config);\n}\n\n/**\n * Host-side map rendering logic for routes.\n */\nexport function handleDrawRoute(\n map: Map,\n miniAppId: string,\n req: DrawRouteRequest,\n) {\n const sourceId = `sdk-route-${miniAppId}`;\n const casingLayerId = `sdk-route-casing-${miniAppId}`;\n const lineLayerId = `sdk-route-line-${miniAppId}`;\n\n const geojson = {\n features: [\n {\n geometry: req.payload.routeData.geometry,\n properties: {},\n type: \"Feature\",\n },\n ],\n type: \"FeatureCollection\",\n };\n\n const source = map.getSource(sourceId);\n if (source) {\n // @ts-expect-error - maplibre-gl types might not expose setData nicely on generic source\n (source as maplibregl.GeoJSONSource).setData(geojson);\n } else {\n map.addSource(sourceId, {\n data: geojson as any,\n type: \"geojson\",\n });\n\n map.addLayer({\n id: casingLayerId,\n layout: {\n \"line-cap\": \"round\",\n \"line-join\": \"round\",\n },\n paint: {\n \"line-color\": \"#111111\",\n \"line-opacity\": 0.8,\n \"line-width\": 8,\n },\n source: sourceId,\n type: \"line\",\n });\n\n map.addLayer({\n id: lineLayerId,\n layout: {\n \"line-cap\": \"round\",\n \"line-join\": \"round\",\n },\n paint: {\n \"line-color\": \"#3b82f6\", // Bright blue\n \"line-width\": 4,\n },\n source: sourceId,\n type: \"line\",\n });\n }\n}\n\nexport function handleClearRoute(map: Map, miniAppId: string) {\n const sourceId = `sdk-route-${miniAppId}`;\n const casingLayerId = `sdk-route-casing-${miniAppId}`;\n const lineLayerId = `sdk-route-line-${miniAppId}`;\n\n if (map.getLayer(lineLayerId)) map.removeLayer(lineLayerId);\n if (map.getLayer(casingLayerId)) map.removeLayer(casingLayerId);\n if (map.getSource(sourceId)) map.removeSource(sourceId);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACWO,IAAM,iBAAiB;AAAA,EAC5B,oBACE,KACA,MACA,SACe;AACf,WAAO;AAAA,MACL,OAAO,EAAE,MAAM,QAAQ;AAAA,MACvB,WAAW,IAAI;AAAA,MACf,YAAY,IAAI;AAAA,MAChB,SAAS;AAAA,MACT,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EAEA,eAAe,KAAa,WAAuC;AACjE,QAAI,QAAQ,GACV,MAAM,GACN,MAAM;AACR,UAAM,cAAkC,CAAC;AACzC,UAAM,QAAQ,MAAM;AAEpB,WAAO,QAAQ,IAAI,QAAQ;AACzB,UAAI,GACF,WAAW,GACX,SAAS;AACX,SAAG;AACD,YAAI,IAAI,WAAW,OAAO,IAAI;AAC9B,mBAAW,IAAI,OAAS;AACxB,oBAAY;AAAA,MACd,SAAS,KAAK;AACd,YAAM,OAAO,SAAS,IAAI,EAAE,UAAU,KAAK,UAAU;AACr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AAM,WAAW,aAAa,SAAS;AACvC,QAAM,gBAAgB,oBAAoB,SAAS;AACnD,QAAM,cAAc,kBAAkB,SAAS;AAE/C,MAAI,IAAI,SAAS,WAAW,EAAG,KAAI,YAAY,WAAW;AAC1D,MAAI,IAAI,SAAS,aAAa,EAAG,KAAI,YAAY,aAAa;AAC9D,MAAI,IAAI,UAAU,QAAQ,EAAG,KAAI,aAAa,QAAQ;AACxD;","names":[]}
|
package/dist/host.js
ADDED
package/dist/host.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Map } from 'maplibre-gl';
|
|
2
|
+
|
|
3
|
+
interface RouteRequest {
|
|
4
|
+
type: "SDK_ROUTING_GETROUTE";
|
|
5
|
+
sdkVersion: string;
|
|
6
|
+
requestId: string;
|
|
7
|
+
payload: {
|
|
8
|
+
origin: [number, number];
|
|
9
|
+
destination: [number, number];
|
|
10
|
+
waypoints?: [number, number][];
|
|
11
|
+
profile: "driving" | "cycling" | "walking";
|
|
12
|
+
language?: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
interface RouteStep {
|
|
16
|
+
instruction: string;
|
|
17
|
+
distance: number;
|
|
18
|
+
duration: number;
|
|
19
|
+
}
|
|
20
|
+
interface RouteResponse {
|
|
21
|
+
type: "SDK_ROUTING_GETROUTE_RESPONSE";
|
|
22
|
+
sdkVersion: string;
|
|
23
|
+
requestId: string;
|
|
24
|
+
success: boolean;
|
|
25
|
+
data?: {
|
|
26
|
+
geometry: GeoJSON.LineString;
|
|
27
|
+
distanceMeters: number;
|
|
28
|
+
durationSeconds: number;
|
|
29
|
+
steps?: RouteStep[];
|
|
30
|
+
};
|
|
31
|
+
error?: {
|
|
32
|
+
code: "NO_ROUTE" | "NETWORK_ERROR" | "INVALID_INPUT" | "BACKEND_ERROR";
|
|
33
|
+
message: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
interface DrawRouteRequest {
|
|
37
|
+
type: "SDK_ROUTING_DRAWROUTE";
|
|
38
|
+
sdkVersion: string;
|
|
39
|
+
requestId: string;
|
|
40
|
+
payload: {
|
|
41
|
+
routeData: NonNullable<RouteResponse["data"]>;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
interface ClearRouteRequest {
|
|
45
|
+
type: "SDK_ROUTING_CLEARROUTE";
|
|
46
|
+
sdkVersion: string;
|
|
47
|
+
requestId: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface RoutingBackendConfig {
|
|
51
|
+
backend: "osrm" | "valhalla";
|
|
52
|
+
baseUrl: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Handles a route request from the mini-app and fetches data from the configured backend.
|
|
57
|
+
*/
|
|
58
|
+
declare function handleRouteRequest(req: RouteRequest, config: RoutingBackendConfig): Promise<RouteResponse>;
|
|
59
|
+
/**
|
|
60
|
+
* Host-side map rendering logic for routes.
|
|
61
|
+
*/
|
|
62
|
+
declare function handleDrawRoute(map: Map, miniAppId: string, req: DrawRouteRequest): void;
|
|
63
|
+
declare function handleClearRoute(map: Map, miniAppId: string): void;
|
|
64
|
+
|
|
65
|
+
export { type ClearRouteRequest as C, type DrawRouteRequest as D, type RouteResponse as R, type RouteStep as a, type RouteRequest as b, type RoutingBackendConfig as c, handleDrawRoute as d, handleRouteRequest as e, handleClearRoute as h };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Map } from 'maplibre-gl';
|
|
2
|
+
|
|
3
|
+
interface RouteRequest {
|
|
4
|
+
type: "SDK_ROUTING_GETROUTE";
|
|
5
|
+
sdkVersion: string;
|
|
6
|
+
requestId: string;
|
|
7
|
+
payload: {
|
|
8
|
+
origin: [number, number];
|
|
9
|
+
destination: [number, number];
|
|
10
|
+
waypoints?: [number, number][];
|
|
11
|
+
profile: "driving" | "cycling" | "walking";
|
|
12
|
+
language?: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
interface RouteStep {
|
|
16
|
+
instruction: string;
|
|
17
|
+
distance: number;
|
|
18
|
+
duration: number;
|
|
19
|
+
}
|
|
20
|
+
interface RouteResponse {
|
|
21
|
+
type: "SDK_ROUTING_GETROUTE_RESPONSE";
|
|
22
|
+
sdkVersion: string;
|
|
23
|
+
requestId: string;
|
|
24
|
+
success: boolean;
|
|
25
|
+
data?: {
|
|
26
|
+
geometry: GeoJSON.LineString;
|
|
27
|
+
distanceMeters: number;
|
|
28
|
+
durationSeconds: number;
|
|
29
|
+
steps?: RouteStep[];
|
|
30
|
+
};
|
|
31
|
+
error?: {
|
|
32
|
+
code: "NO_ROUTE" | "NETWORK_ERROR" | "INVALID_INPUT" | "BACKEND_ERROR";
|
|
33
|
+
message: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
interface DrawRouteRequest {
|
|
37
|
+
type: "SDK_ROUTING_DRAWROUTE";
|
|
38
|
+
sdkVersion: string;
|
|
39
|
+
requestId: string;
|
|
40
|
+
payload: {
|
|
41
|
+
routeData: NonNullable<RouteResponse["data"]>;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
interface ClearRouteRequest {
|
|
45
|
+
type: "SDK_ROUTING_CLEARROUTE";
|
|
46
|
+
sdkVersion: string;
|
|
47
|
+
requestId: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface RoutingBackendConfig {
|
|
51
|
+
backend: "osrm" | "valhalla";
|
|
52
|
+
baseUrl: string;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Handles a route request from the mini-app and fetches data from the configured backend.
|
|
57
|
+
*/
|
|
58
|
+
declare function handleRouteRequest(req: RouteRequest, config: RoutingBackendConfig): Promise<RouteResponse>;
|
|
59
|
+
/**
|
|
60
|
+
* Host-side map rendering logic for routes.
|
|
61
|
+
*/
|
|
62
|
+
declare function handleDrawRoute(map: Map, miniAppId: string, req: DrawRouteRequest): void;
|
|
63
|
+
declare function handleClearRoute(map: Map, miniAppId: string): void;
|
|
64
|
+
|
|
65
|
+
export { type ClearRouteRequest as C, type DrawRouteRequest as D, type RouteResponse as R, type RouteStep as a, type RouteRequest as b, type RoutingBackendConfig as c, handleDrawRoute as d, handleRouteRequest as e, handleClearRoute as h };
|