@pipedream/mapbox 0.0.3 → 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 CHANGED
@@ -1,12 +1,11 @@
1
1
  # Overview
2
2
 
3
- Mapbox is a powerful mapping platform that enables developers to create
4
- interactive maps for a variety of purposes. Here are some examples of what you
5
- can build with the Mapbox API:
6
-
7
- - A web map with zoom and pan controls
8
- - A map with markers and popups
9
- - A map with geolocation
10
- - A heatmap
11
- - A choropleth map
12
- - A map with custom tiles
3
+ The Mapbox API offers a suite of tools for developers to integrate location-based services into their applications. With Pipedream, you can leverage Mapbox's capabilities to create complex automations and workflows, like real-time mapping, geocoding, and route optimization. Whether you're managing delivery routes, analyzing spatial data, or personalizing user experiences based on location, Mapbox provides the geographical intelligence that, when combined with Pipedream's serverless platform, can turn these ideas into efficient, automated processes.
4
+
5
+ # Example Use Cases
6
+
7
+ - **Customer Order Tracking**: When a customer places an order, automate the process of sending them real-time updates on the delivery driver's location. Use Mapbox to track the driver and Pipedream's workflow to trigger emails or SMS notifications via Twilio to the customer at key points along the route.
8
+
9
+ - **Localized Content Delivery**: Tailor the user experience by serving location-specific content. When a user visits your site, use their IP address to determine their location with Mapbox and serve up local news, weather, or personalized recommendations. This workflow could include a connection to a CMS like WordPress to pull the relevant content.
10
+
11
+ - **Efficient Dispatch System**: Optimize dispatching for services like taxi or delivery by using Mapbox's routing capabilities. When a service request comes in, Pipedream can use Mapbox to calculate the nearest available driver and the quickest route to the customer, then communicate the dispatch details through Slack or another messaging service to coordinate the pickup.
@@ -0,0 +1,101 @@
1
+ import mapbox from "../../mapbox.app.mjs";
2
+ import { getFileStreamAndMetadata } from "@pipedream/platform";
3
+ import FormData from "form-data";
4
+
5
+ export default {
6
+ key: "mapbox-create-tileset",
7
+ name: "Create Tileset",
8
+ description: "Uploads and creates a new tileset from a data source. [See the documentation](https://docs.mapbox.com/api/maps/mapbox-tiling-service/)",
9
+ version: "0.1.0",
10
+ type: "action",
11
+ props: {
12
+ mapbox,
13
+ username: {
14
+ type: "string",
15
+ label: "Username",
16
+ description: "The Mapbox username of the account for which to create a tileset source",
17
+ },
18
+ tilesetName: {
19
+ type: "string",
20
+ label: "Tileset Name",
21
+ description: "A unique name for the tileset source to be created. Limited to 32 characters. The only allowed special characters are `-` (hyphen) and `_` (underscore)",
22
+ },
23
+ filePath: {
24
+ type: "string",
25
+ label: "File Path or URL",
26
+ description: "A tileset source file. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`)",
27
+ },
28
+ recipe: {
29
+ type: "object",
30
+ label: "Recipe",
31
+ description: "A recipe that describes how the GeoJSON data you uploaded should be transformed into tiles. A tileset source is raw geographic data formatted as [line-delimited GeoJSON](https://en.wikipedia.org/wiki/JSON_streaming#Line-delimited_JSON), or a supported [raster file format](https://docs.mapbox.com/mapbox-tiling-service/raster/supported-file-formats/). For more information on how to create and format recipes, see the [Recipe reference](https://docs.mapbox.com/mapbox-tiling-service/reference/) and [Recipe examples](https://docs.mapbox.com/mapbox-tiling-service/examples/).",
32
+ },
33
+ description: {
34
+ type: "string",
35
+ label: "Description",
36
+ description: "A description of the tileset",
37
+ optional: true,
38
+ },
39
+ private: {
40
+ type: "boolean",
41
+ label: "Private",
42
+ description: "Describes whether the tileset must be used with an access token from your Mapbox account. Default is `true`.",
43
+ optional: true,
44
+ },
45
+ },
46
+ async run({ $ }) {
47
+ // Create Tileset Source
48
+ try {
49
+ const fileData = new FormData();
50
+ const {
51
+ stream, metadata,
52
+ } = await getFileStreamAndMetadata(this.filePath);
53
+ fileData.append("file", stream, {
54
+ contentType: metadata.contentType,
55
+ knownLength: metadata.size,
56
+ filename: metadata.name,
57
+ });
58
+
59
+ await this.mapbox.createTilesetSource({
60
+ $,
61
+ username: this.username,
62
+ id: this.tilesetName,
63
+ data: fileData,
64
+ headers: fileData.getHeaders(),
65
+ });
66
+ } catch (e) {
67
+ throw new Error(`Error uploading file: \`${this.filePath}\`. Error: ${e}`);
68
+ }
69
+
70
+ const recipe = typeof this.recipe === "string"
71
+ ? JSON.parse(this.recipe)
72
+ : this.recipe;
73
+
74
+ // Validate Recipe
75
+ const {
76
+ valid, errors,
77
+ } = await this.mapbox.validateRecipe({
78
+ $,
79
+ data: recipe,
80
+ });
81
+
82
+ if (!valid) {
83
+ throw new Error(`Error validating recipe: ${errors}`);
84
+ }
85
+
86
+ // Create Tileset
87
+ const response = await this.mapbox.createTileset({
88
+ $,
89
+ tilesetId: `${this.username}.${this.tilesetName}`,
90
+ data: {
91
+ recipe,
92
+ name: this.tilesetName,
93
+ description: this.description,
94
+ private: this.private,
95
+ },
96
+ });
97
+
98
+ $.export("$summary", `Created tileset ${this.tilesetName}`);
99
+ return response;
100
+ },
101
+ };
@@ -0,0 +1,60 @@
1
+ import mapbox from "../../mapbox.app.mjs";
2
+
3
+ export default {
4
+ key: "mapbox-generate-directions",
5
+ name: "Generate Directions",
6
+ description: "Generates directions between two or more locations using Mapbox API. [See the documentation](https://docs.mapbox.com/api/navigation/directions/).",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ props: {
10
+ mapbox,
11
+ startCoordinate: {
12
+ type: "string",
13
+ label: "Start Coordinate",
14
+ description: "The starting point in the format `longitude,latitude`, E.g. `-85.244869,37.835819`",
15
+ },
16
+ endCoordinate: {
17
+ type: "string",
18
+ label: "End Coordinate",
19
+ description: "The ending point in the format `longitude,latitude`, E.g. `-85.244869,37.835819`",
20
+ },
21
+ transportationMode: {
22
+ propDefinition: [
23
+ mapbox,
24
+ "transportationMode",
25
+ ],
26
+ },
27
+ steps: {
28
+ type: "boolean",
29
+ label: "Steps",
30
+ description: "Whether to return steps and turn-by-turn instructions (`true`) or not (`false`, default)",
31
+ optional: true,
32
+ },
33
+ alternatives: {
34
+ type: "boolean",
35
+ label: "Alternatives",
36
+ description: "Whether to try to return alternative routes (`true`) or not (`false`, default). An alternative route is a route that is significantly different from the fastest route, but still close in time.",
37
+ optional: true,
38
+ },
39
+ exclude: {
40
+ propDefinition: [
41
+ mapbox,
42
+ "exclude",
43
+ ],
44
+ },
45
+ },
46
+ async run({ $ }) {
47
+ const directions = await this.mapbox.getDirections({
48
+ $,
49
+ transportationMode: this.transportationMode,
50
+ coordinates: `${this.startCoordinate};${this.endCoordinate}`,
51
+ params: {
52
+ steps: this.steps,
53
+ alternatives: this.alternatives,
54
+ exclude: this.exclude && this.exclude.join(","),
55
+ },
56
+ });
57
+ $.export("$summary", "Generated directions successfully.");
58
+ return directions;
59
+ },
60
+ };
@@ -0,0 +1,41 @@
1
+ import mapbox from "../../mapbox.app.mjs";
2
+
3
+ export default {
4
+ key: "mapbox-geocode-address",
5
+ name: "Geocode Address",
6
+ description: "Retrieves the geocoded location for a given address. [See the documentation](https://docs.mapbox.com/api/search/geocoding/)",
7
+ version: "0.0.1",
8
+ type: "action",
9
+ props: {
10
+ mapbox,
11
+ address: {
12
+ type: "string",
13
+ label: "Address",
14
+ description: "The address (or partial address) to geocode. This could be an address, a city name, etc. Must consist of at most 20 words and numbers separated by spacing and punctuation, and at most 256 characters.",
15
+ },
16
+ boundingBox: {
17
+ type: "string",
18
+ label: "Bounding Box",
19
+ description: "Limit results to only those contained within the supplied bounding box. Bounding boxes should be supplied as four numbers separated by commas, in `minLon,minLat,maxLon,maxLat` order. The bounding box cannot cross the 180th meridian. You can use the [Location Helper](https://labs.mapbox.com/location-helper) to find a bounding box for use with this API.",
20
+ optional: true,
21
+ },
22
+ proximity: {
23
+ type: "string",
24
+ label: "Proximity",
25
+ description: "Bias the response to favor results that are closer to this location. Provided as two comma-separated coordinates in `longitude,latitude` order.",
26
+ optional: true,
27
+ },
28
+ },
29
+ async run({ $ }) {
30
+ const response = await this.mapbox.geocode({
31
+ $,
32
+ params: {
33
+ q: this.address,
34
+ bBox: this.boundingBox,
35
+ proximity: this.proximity,
36
+ },
37
+ });
38
+ $.export("$summary", `Geocoded location for "${this.address}" retrieved successfully`);
39
+ return response;
40
+ },
41
+ };
@@ -0,0 +1,21 @@
1
+ const TRANSPORTATION_MODES = [
2
+ "driving",
3
+ "walking",
4
+ "cycling",
5
+ "driving-traffic",
6
+ ];
7
+
8
+ const EXCLUDE_OPTIONS = [
9
+ "motorway",
10
+ "toll",
11
+ "ferry",
12
+ "unpaved",
13
+ "cash_only_tolls",
14
+ "country_border",
15
+ "state_border",
16
+ ];
17
+
18
+ export default {
19
+ TRANSPORTATION_MODES,
20
+ EXCLUDE_OPTIONS,
21
+ };
package/mapbox.app.mjs ADDED
@@ -0,0 +1,81 @@
1
+ import { axios } from "@pipedream/platform";
2
+ import constants from "./common/constants.mjs";
3
+
4
+ export default {
5
+ type: "app",
6
+ app: "mapbox",
7
+ propDefinitions: {
8
+ transportationMode: {
9
+ type: "string",
10
+ label: "Transportation Mode",
11
+ description: "The mode of transportation",
12
+ options: constants.TRANSPORTATION_MODES,
13
+ },
14
+ exclude: {
15
+ type: "string[]",
16
+ label: "Exclude",
17
+ description: "Exclude certain road types and custom locations from routing",
18
+ options: constants.EXCLUDE_OPTIONS,
19
+ optional: true,
20
+ },
21
+ },
22
+ methods: {
23
+ _baseUrl() {
24
+ return "https://api.mapbox.com";
25
+ },
26
+ _makeRequest({
27
+ $ = this,
28
+ path,
29
+ params,
30
+ ...otherOpts
31
+ }) {
32
+ return axios($, {
33
+ url: `${this._baseUrl()}${path}`,
34
+ params: {
35
+ access_token: this.$auth.access_token,
36
+ ...params,
37
+ },
38
+ ...otherOpts,
39
+ });
40
+ },
41
+ geocode(opts = {}) {
42
+ return this._makeRequest({
43
+ path: "/search/geocode/v6/forward",
44
+ ...opts,
45
+ });
46
+ },
47
+ getDirections({
48
+ transportationMode, coordinates, ...opts
49
+ }) {
50
+ return this._makeRequest({
51
+ path: `/directions/v5/mapbox/${transportationMode}/${coordinates}`,
52
+ ...opts,
53
+ });
54
+ },
55
+ createTilesetSource({
56
+ username, id, ...opts
57
+ }) {
58
+ return this._makeRequest({
59
+ method: "POST",
60
+ path: `/tilesets/v1/sources/${username}/${id}`,
61
+ ...opts,
62
+ });
63
+ },
64
+ validateRecipe(opts = {}) {
65
+ return this._makeRequest({
66
+ method: "PUT",
67
+ path: "/tilesets/v1/validateRecipe",
68
+ ...opts,
69
+ });
70
+ },
71
+ createTileset({
72
+ tilesetId, ...opts
73
+ }) {
74
+ return this._makeRequest({
75
+ method: "POST",
76
+ path: `/tilesets/v1/${tilesetId}`,
77
+ ...opts,
78
+ });
79
+ },
80
+ },
81
+ };
package/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "@pipedream/mapbox",
3
- "version": "0.0.3",
3
+ "version": "0.2.0",
4
4
  "description": "Pipedream Mapbox Components",
5
- "main": "dist/app/mapbox.app.mjs",
5
+ "main": "mapbox.app.mjs",
6
6
  "keywords": [
7
7
  "pipedream",
8
8
  "mapbox"
9
9
  ],
10
- "files": [
11
- "dist"
12
- ],
13
10
  "homepage": "https://pipedream.com/apps/mapbox",
14
11
  "author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
15
12
  "publishConfig": {
16
13
  "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@pipedream/platform": "^3.1.0",
17
+ "form-data": "^4.0.1"
17
18
  }
18
19
  }