@pipedream/mapbox 0.0.2 → 0.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/LICENSE CHANGED
@@ -1,7 +1,41 @@
1
- Copyright 2020 Pipedream, Inc.
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Pipedream Source Available License Version 1.0
2
+
3
+ This Pipedream Source Available License Agreement Version 1.0 (this “Agreement”) sets forth the terms on which Pipedream, Inc., a Delaware corporation (“Pipedream”) makes available certain software (the Software). By installing, downloading, accessing, using or distributing the Software, you agree to the terms of this Agreement. If you do not agree to such terms, you must not use the Software. If you are receiving the Software on behalf of a legal entity, you represent and warrant that you have the actual authority to agree to the terms and conditions of this Agreement on behalf of such entity. “Licensee” means you, an individual, or the entity on whose behalf you are receiving the Software.
4
+
5
+ LICENSE GRANT AND CONDITIONS.
6
+
7
+ 1.1 License. Subject to the terms and conditions of this Agreement, Pipedream hereby grants to Licensee a non-exclusive, royalty-free, worldwide, non-transferable, non-sublicenseable license during the term of this Agreement to use, prepare modifications and derivative works, distribute (including without limitation in source code or object code form) and reproduce copies of the Software (the “License”). Licensee is not granted the right to, and Licensee shall not, exercise the License for an Excluded Purpose. For purposes of this Agreement, “Excluded Purpose” means any commercial use of the software including, but not limited to, making available any software-as-a-service, platform-as-a-service, infrastructure-as-a-service or other online service that competes with the Software or any other Pipedream products or services.
8
+
9
+ 1.2 Conditions. In consideration of the License, Licensee’s distribution of the Software is subject to the following conditions:
10
+
11
+ a. Licensee must cause any Software modified by Licensee to carry prominent notices stating that Licensee modified the Software.
12
+
13
+ b. On each Software copy, Licensee shall reproduce and not remove or alter all Pipedream or third party copyright or other proprietary notices contained in the Software, and Licensee must provide this with each copy: “This software is made available by Pipedream, Inc., under the terms of the Pipedream Source Available License, Version 1.0 located at https://github.com/PipedreamHQ/pipedream/blob/master/LICENSE. By installing, downloading, accessing, using or distributing the Software, you agree to the terms of such License Agreement.”
14
+
15
+ 1.3 Modifications. Licensee may add its own copyright notices to modifications made by Licensee and may provide additional or different license terms and conditions for use, reproduction, or distribution of Licensee’s modifications. While redistributing the Software or modifications thereof, Licensee may choose to offer, for a fee or free of charge, support, warranty, indemnity, or other obligations. Licensee, and not Pipedream, will be responsible for any such obligations.
16
+
17
+ 1.4 No Sublicensing. The License does not include the right to sublicense the Software; provided, however, that any recipient to which Licensee provides the Software may exercise the License so long as such recipient agrees to the terms and conditions of this Agreement.
18
+
19
+ TERM AND TERMINATION.
20
+
21
+ This Agreement will continue unless and until earlier terminated as set forth herein. If Licensee breaches any of its conditions or obligations under this Agreement, this Agreement will terminate automatically and the License will terminate automatically and permanently.
22
+
23
+ INTELLECTUAL PROPERTY.
24
+
25
+ As between the parties, Pipedream retains all right, title, and interest in the Software, and all intellectual property rights therein. Pipedream hereby reserves all rights not expressly granted to Licensee in this Agreement. Pipedream reserves all rights in its trademarks and service marks, and no licenses thereto are granted by this Agreement.
26
+
27
+ DISCLAIMER.
28
+
29
+ PIPEDREAM HEREBY DISCLAIMS ANY AND ALL WARRANTIES AND CONDITIONS, EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, AND SPECIFICALLY DISCLAIMS ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE SOFTWARE.
30
+
31
+ LIMITATION OF LIABILITY.
32
+
33
+ PIPEDREAM WILL NOT BE LIABLE FOR ANY DAMAGES OF ANY KIND, INCLUDING BUT NOT LIMITED TO, LOST PROFITS OR ANY CONSEQUENTIAL, SPECIAL, INCIDENTAL, INDIRECT, OR DIRECT DAMAGES, HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, ARISING OUT OF THIS AGREEMENT. THE FOREGOING SHALL APPLY TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW.
34
+
35
+ GENERAL.
36
+
37
+ 6.1 Governing Law. This Agreement will be governed by and interpreted in accordance with the laws of the state of California, without reference to its conflict of laws principles. If Licensee is located outside of the United States, any dispute, controversy or claim arising out of or relating to this Agreement will be referred to and finally determined by arbitration in accordance with the JAMS International Arbitration Rules. The tribunal will consist of one arbitrator. Judgment upon the award rendered by the arbitrator may be entered in any court having jurisdiction thereof. All disputes including arbitrations shall take place in Santa Clara County, California. The language to be used in any such proceedings shall be English.
38
+
39
+ 6.2. Assignment. Licensee is not authorized to assign its rights under this Agreement to any third party. Pipedream may freely assign its rights under this Agreement to any third party.
40
+
41
+ 6.3. Other. This Agreement is the entire agreement between the parties regarding the subject matter hereof. No amendment or modification of this Agreement will be valid or binding upon the parties unless made in writing and signed by the duly authorized representatives of both parties. In the event that any provision, including without limitation any condition, of this Agreement is held to be unenforceable, this Agreement and all licenses and rights granted hereunder will immediately terminate. Waiver by Pipedream of a breach of any provision of this Agreement or the failure by Pipedream to exercise any right hereunder will not be construed as a waiver of any subsequent breach of that right or as a waiver of any other right.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # Overview
2
+
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,99 @@
1
+ import mapbox from "../../mapbox.app.mjs";
2
+ import fs from "fs";
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.0.1",
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",
26
+ description: "The path to a tileset source file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
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
+ const filePath = this.filePath.includes("tmp/")
48
+ ? this.filePath
49
+ : `/tmp/${this.filePath}`;
50
+
51
+ // Create Tileset Source
52
+ try {
53
+ const fileData = new FormData();
54
+ const content = fs.createReadStream(filePath);
55
+ fileData.append("file", content);
56
+
57
+ await this.mapbox.createTilesetSource({
58
+ $,
59
+ username: this.username,
60
+ id: this.tilesetName,
61
+ data: fileData,
62
+ headers: fileData.getHeaders(),
63
+ });
64
+ } catch (e) {
65
+ throw new Error(`Error uploading file: \`${filePath}\`. Error: ${e}`);
66
+ }
67
+
68
+ const recipe = typeof this.recipe === "string"
69
+ ? JSON.parse(this.recipe)
70
+ : this.recipe;
71
+
72
+ // Validate Recipe
73
+ const {
74
+ valid, errors,
75
+ } = await this.mapbox.validateRecipe({
76
+ $,
77
+ data: recipe,
78
+ });
79
+
80
+ if (!valid) {
81
+ throw new Error(`Error validating recipe: ${errors}`);
82
+ }
83
+
84
+ // Create Tileset
85
+ const response = await this.mapbox.createTileset({
86
+ $,
87
+ tilesetId: `${this.username}.${this.tilesetName}`,
88
+ data: {
89
+ recipe,
90
+ name: this.tilesetName,
91
+ description: this.description,
92
+ private: this.private,
93
+ },
94
+ });
95
+
96
+ $.export("$summary", `Created tileset ${this.tilesetName}`);
97
+ return response;
98
+ },
99
+ };
@@ -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,19 +1,19 @@
1
1
  {
2
2
  "name": "@pipedream/mapbox",
3
- "version": "0.0.2",
3
+ "version": "0.1.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
- "license": "MIT",
16
12
  "publishConfig": {
17
13
  "access": "public"
14
+ },
15
+ "dependencies": {
16
+ "@pipedream/platform": "^3.0.3",
17
+ "form-data": "^4.0.1"
18
18
  }
19
19
  }