diff --git a/components/ipstack/actions/ip-lookup/ip-lookup.mjs b/components/ipstack/actions/ip-lookup/ip-lookup.mjs new file mode 100644 index 0000000000000..928899431a5db --- /dev/null +++ b/components/ipstack/actions/ip-lookup/ip-lookup.mjs @@ -0,0 +1,53 @@ +import app from "../../ipstack.app.mjs"; + +export default { + key: "ipstack-ip-lookup", + name: "IP Lookup", + description: "Look up single IPv4 or IPv6 addresses. [See the documentation](https://ipstack.com/documentation#standard)", + version: "0.0.1", + type: "action", + props: { + app, + ip: { + propDefinition: [ + app, + "ip", + ], + }, + hostname: { + propDefinition: [ + app, + "hostname", + ], + }, + security: { + propDefinition: [ + app, + "security", + ], + }, + language: { + propDefinition: [ + app, + "language", + ], + }, + }, + async run({ $ }) { + const response = await this.app.ipLookup({ + $, + ip: this.ip, + params: { + hostname: this.hostname + ? 1 + : 0, + security: this.security + ? 1 + : 0, + language: this.language, + }, + }); + $.export("$summary", "Successfully retrieved data for the IP " + this.ip); + return response; + }, +}; diff --git a/components/ipstack/common/constants.mjs b/components/ipstack/common/constants.mjs new file mode 100644 index 0000000000000..5b76f18c05cd8 --- /dev/null +++ b/components/ipstack/common/constants.mjs @@ -0,0 +1,37 @@ +export default { + + LANGUAGE_OPTIONS: [ + { + value: "en", + label: "English/US", + }, + { + value: "de", + label: "German", + }, + { + value: "es", + label: "Spanish", + }, + { + value: "fr", + label: "French", + }, + { + value: "ja", + label: "Japanese", + }, + { + value: "pt-br", + label: "Portugues (Brazil)", + }, + { + value: "ru", + label: "Russian", + }, + { + value: "zh", + label: "Chinese", + }, + ], +}; diff --git a/components/ipstack/ipstack.app.mjs b/components/ipstack/ipstack.app.mjs index 1fc13841d29a4..db33c4a10107e 100644 --- a/components/ipstack/ipstack.app.mjs +++ b/components/ipstack/ipstack.app.mjs @@ -1,11 +1,63 @@ +import { axios } from "@pipedream/platform"; +import constants from "./common/constants.mjs"; + export default { type: "app", app: "ipstack", - propDefinitions: {}, + propDefinitions: { + ip: { + type: "string", + label: "IP", + description: "IPv4 or IPv6 address to be looked up", + }, + hostname: { + type: "boolean", + label: "Hostname", + description: "If set to `true`, hostname lookup will be included in the API response", + optional: true, + }, + security: { + type: "boolean", + label: "Security", + description: "If set to `true`, includes security module in the API response", + optional: true, + }, + language: { + type: "string", + label: "Language", + description: "Output language using 2-letter ISO 639-1 format", + optional: true, + options: constants.LANGUAGE_OPTIONS, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.ipstack.com"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + params, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + params: { + access_key: `${this.$auth.access_key}`, + ...params, + }, + }); + }, + + async ipLookup({ + ip, ...args + }) { + return this._makeRequest({ + path: `/${ip}`, + ...args, + }); }, }, }; diff --git a/components/ipstack/package.json b/components/ipstack/package.json index 2617bd1644127..ce061714f1f13 100644 --- a/components/ipstack/package.json +++ b/components/ipstack/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/ipstack", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream ipstack Components", "main": "ipstack.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bdc46d3c9845a..9358dc537fe0d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6809,7 +6809,11 @@ importers: specifier: ^1.1.1 version: 1.6.6 - components/ipstack: {} + components/ipstack: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/iqair_airvisual: {}