diff --git a/components/bigdatacorp/actions/get-address-data/get-address-data.mjs b/components/bigdatacorp/actions/get-address-data/get-address-data.mjs new file mode 100644 index 0000000000000..b2711bd94bfc3 --- /dev/null +++ b/components/bigdatacorp/actions/get-address-data/get-address-data.mjs @@ -0,0 +1,47 @@ +import app from "../../bigdatacorp.app.mjs"; +import constants from "../../common/constants.mjs"; + +export default { + key: "bigdatacorp-get-address-data", + name: "Get Address Data", + description: "Returns the available data for a Zipcode number according to the selected dataset. [See the documentation](https://docs.bigdatacorp.com.br/plataforma/reference/enderecos_legal_amazon)", + version: "0.0.1", + type: "action", + props: { + app, + doc: { + propDefinition: [ + app, + "doc", + ], + description: "Zipcode of the address you want to search for, i.e.: `88048-656`", + }, + dataset: { + propDefinition: [ + app, + "dataset", + ], + options: constants.ADDRESS_DATASETS, + }, + }, + + async run({ $ }) { + const response = await this.app.getAddressData({ + $, + data: { + Datasets: this.dataset, + q: `zipcode[${this.doc}]`, + }, + }); + + const status = response.Status[this.dataset][0].Message; + + if (status === "OK") { + $.export("$summary", `Successfully sent the request for the '${this.dataset}' dataset. Status: ${status}`); + } else { + throw new Error(status); + } + + return response; + }, +}; diff --git a/components/bigdatacorp/actions/get-company-data/get-company-data.mjs b/components/bigdatacorp/actions/get-company-data/get-company-data.mjs new file mode 100644 index 0000000000000..836e8be0d6af7 --- /dev/null +++ b/components/bigdatacorp/actions/get-company-data/get-company-data.mjs @@ -0,0 +1,47 @@ +import app from "../../bigdatacorp.app.mjs"; +import constants from "../../common/constants.mjs"; + +export default { + key: "bigdatacorp-get-company-data", + name: "Get Company Data", + description: "Returns the available data for a CNPJ number according to the selected dataset. [See the documentation](https://docs.bigdatacorp.com.br/plataforma/reference/empresas_emails_extended)", + version: "0.0.1", + type: "action", + props: { + app, + doc: { + propDefinition: [ + app, + "doc", + ], + description: "Document Number of the entity you want to search for, i.e.: `27.823.957/0001-94`", + }, + dataset: { + propDefinition: [ + app, + "dataset", + ], + options: constants.COMPANY_DATASETS, + }, + }, + + async run({ $ }) { + const response = await this.app.getCompanyData({ + $, + data: { + Datasets: this.dataset, + q: `doc{${this.doc}}`, + }, + }); + + const status = response.Status[this.dataset][0].Message; + + if (status === "OK") { + $.export("$summary", `Successfully sent the request for the '${this.dataset}' dataset. Status: ${status}`); + } else { + throw new Error(status); + } + + return response; + }, +}; diff --git a/components/bigdatacorp/actions/get-person-data/get-person-data.mjs b/components/bigdatacorp/actions/get-person-data/get-person-data.mjs new file mode 100644 index 0000000000000..cfc3e084ce04b --- /dev/null +++ b/components/bigdatacorp/actions/get-person-data/get-person-data.mjs @@ -0,0 +1,47 @@ +import app from "../../bigdatacorp.app.mjs"; +import constants from "../../common/constants.mjs"; + +export default { + key: "bigdatacorp-get-person-data", + name: "Get Person Data", + description: "Returns the available data for a CPF number according to the selected dataset. [See the documentation](https://docs.bigdatacorp.com.br/plataforma/reference/pessoas_registration_data)", + version: "0.0.1", + type: "action", + props: { + app, + doc: { + propDefinition: [ + app, + "doc", + ], + description: "Document Number of the entity you want to search for, i.e.: `128.982.560-21`", + }, + dataset: { + propDefinition: [ + app, + "dataset", + ], + options: constants.PERSON_DATASETS, + }, + }, + + async run({ $ }) { + const response = await this.app.getPersonData({ + $, + data: { + Datasets: this.dataset, + q: `doc{${this.doc}}`, + }, + }); + + const status = response.Status[this.dataset][0].Message; + + if (status === "OK") { + $.export("$summary", `Successfully sent the request for the '${this.dataset}' dataset. Status: ${status}`); + } else { + throw new Error(status); + } + + return response; + }, +}; diff --git a/components/bigdatacorp/bigdatacorp.app.mjs b/components/bigdatacorp/bigdatacorp.app.mjs index 16b8bf9fbcc5f..57131a5ba0ff9 100644 --- a/components/bigdatacorp/bigdatacorp.app.mjs +++ b/components/bigdatacorp/bigdatacorp.app.mjs @@ -1,11 +1,62 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "bigdatacorp", - propDefinitions: {}, + propDefinitions: { + doc: { + type: "string", + label: "Document Number", + description: "Document Number of the entity you want to search for", + }, + dataset: { + type: "string", + label: "Dataset", + description: "The target dataset to which the query will be sent", + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://plataforma.bigdatacorp.com.br"; + }, + async _makeRequest(opts = {}) { + const { + $ = this, + path, + headers, + ...otherOpts + } = opts; + return axios($, { + ...otherOpts, + url: this._baseUrl() + path, + headers: { + ...headers, + "Accept": "application/json", + "AccessToken": `${this.$auth.access_token}`, + "TokenId": `${this.$auth.token_id}`, + }, + }); + }, + async getPersonData(args = {}) { + return this._makeRequest({ + path: "/pessoas", + method: "post", + ...args, + }); + }, + async getCompanyData(args = {}) { + return this._makeRequest({ + path: "/empresas", + method: "post", + ...args, + }); + }, + async getAddressData(args = {}) { + return this._makeRequest({ + path: "/enderecos", + method: "post", + ...args, + }); }, }, }; diff --git a/components/bigdatacorp/common/constants.mjs b/components/bigdatacorp/common/constants.mjs new file mode 100644 index 0000000000000..1fd6dac89cfff --- /dev/null +++ b/components/bigdatacorp/common/constants.mjs @@ -0,0 +1,92 @@ +export default { + PERSON_DATASETS: [ + { + "value": "emails_extended", + "label": "Emails", + }, + { + "value": "phones_extended", + "label": "Phones", + }, + { + "value": "registration_data", + "label": "Registration Data", + }, + { + "value": "related_people_emails", + "label": "Related People Emails", + }, + { + "value": "related_people_phones", + "label": "Related People Phones", + }, + { + "value": "related_people_addresses", + "label": "Related People Addresses", + }, + { + "value": "vehicles", + "label": "Vehicles", + }, + ], + COMPANY_DATASETS: [ + { + "value": "emails_extended", + "label": "Emails", + }, + { + "value": "phones_extended", + "label": "Phones", + }, + { + "value": "registration_data", + "label": "Registration Data", + }, + { + "value": "related_people_emails", + "label": "Related People Emails", + }, + { + "value": "related_people_phones", + "label": "Related People Phones", + }, + { + "value": "related_people_addresses", + "label": "Related People Addresses", + }, + { + "value": "political_involvement", + "label": "Political Involvement", + }, + { + "value": "online_ads", + "label": "Online Ads", + }, + ], + ADDRESS_DATASETS: [ + { + "value": "legal_amazon", + "label": "Legal Amazon", + }, + { + "value": "environmental_preservation_areas", + "label": "Enviromental Preservation Areas", + }, + { + "value": "biomes_data", + "label": "Biomes Data", + }, + { + "value": "embargoed_areas", + "label": "Embargoed Areas", + }, + { + "value": "legal_reserve", + "label": "Legal Reserve", + }, + { + "value": "basic_data", + "label": "Basic Data", + }, + ], +}; diff --git a/components/bigdatacorp/package.json b/components/bigdatacorp/package.json index ad87cda43efd4..540c048f2279a 100644 --- a/components/bigdatacorp/package.json +++ b/components/bigdatacorp/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/bigdatacorp", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream BigDataCorp Components", "main": "bigdatacorp.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.0.3" } -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d7b40a5200526..f5f157fbeec1a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1132,7 +1132,11 @@ importers: specifier: ^4.0.0 version: 4.0.1 - components/bigdatacorp: {} + components/bigdatacorp: + dependencies: + '@pipedream/platform': + specifier: ^3.0.3 + version: 3.0.3 components/bigmailer: dependencies: @@ -6637,8 +6641,7 @@ importers: specifier: ^3.0.3 version: 3.0.3 - components/motive: - specifiers: {} + components/motive: {} components/moxie: dependencies: @@ -10821,8 +10824,7 @@ importers: specifier: ^1.5.1 version: 1.6.6 - components/traffit: - specifiers: {} + components/traffit: {} components/trainual: {}