diff --git a/components/accuranker/accuranker.app.mjs b/components/accuranker/accuranker.app.mjs index 61c7679581a2c..24c50f8cbf9c1 100644 --- a/components/accuranker/accuranker.app.mjs +++ b/components/accuranker/accuranker.app.mjs @@ -1,11 +1,127 @@ +import { axios } from "@pipedream/platform"; +const DEFAULT_LIMIT = 100; + export default { type: "app", app: "accuranker", - propDefinitions: {}, + propDefinitions: { + domainId: { + type: "string", + label: "Domain ID", + description: "The ID of the domain", + async options({ page }) { + const { results: domains } = await this.listDomains({ + params: { + limit: DEFAULT_LIMIT, + offset: DEFAULT_LIMIT * page, + fields: "id,domain", + }, + }); + return domains?.map((domain) => ({ + label: domain.domain, + value: domain.id, + })) || []; + }, + }, + keywordId: { + type: "string", + label: "Keyword ID", + description: "The ID of the keyword", + async options({ + domainId, page, + }) { + const { results: keywords } = await this.listKeywords({ + domainId, + params: { + limit: DEFAULT_LIMIT, + offset: DEFAULT_LIMIT * page, + fields: "id,keyword", + }, + }); + return keywords?.map((keyword) => ({ + label: keyword.keyword, + value: keyword.id, + })) || []; + }, + }, + periodFrom: { + type: "string", + label: "Period From", + description: "Date in format: YYYY-MM-DD", + optional: true, + }, + periodTo: { + type: "string", + label: "Period To", + description: "Date in format: YYYY-MM-DD", + optional: true, + }, + max: { + type: "integer", + label: "Max", + description: "Maximum number of results to return", + optional: true, + default: 100, + }, + }, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://app.accuranker.com/api/v4"; + }, + _makeRequest({ + $ = this, path, ...opts + }) { + return axios($, { + url: `${this._baseUrl()}${path}`, + headers: { + Authorization: `Bearer ${this.$auth.oauth_access_token}`, + }, + ...opts, + }); + }, + listDomains(opts = {}) { + return this._makeRequest({ + path: "/domains/", + ...opts, + }); + }, + listKeywords({ + domainId, ...opts + }) { + return this._makeRequest({ + path: `/domains/${domainId}/keywords/`, + ...opts, + }); + }, + listBrands(opts = {}) { + return this._makeRequest({ + path: "/brands/", + ...opts, + }); + }, + async *paginate({ + fn, args, max, + }) { + args = { + ...args, + params: { + ...args?.params, + limit: DEFAULT_LIMIT, + }, + }; + + let total, count = 0; + do { + const { results } = await fn(args); + for (const item of results) { + yield item; + if (max && ++count >= max) { + return count; + } + } + total = results?.length; + args.params.offset += DEFAULT_LIMIT; + } while (total === DEFAULT_LIMIT); }, }, }; diff --git a/components/accuranker/actions/list-brands/list-brands.mjs b/components/accuranker/actions/list-brands/list-brands.mjs new file mode 100644 index 0000000000000..64defbd91bf5f --- /dev/null +++ b/components/accuranker/actions/list-brands/list-brands.mjs @@ -0,0 +1,75 @@ +import accuranker from "../../accuranker.app.mjs"; + +export default { + key: "accuranker-list-brands", + name: "List Brands", + description: "List brands in Accuranker. [See the documentation](https://app.accuranker.com/api/read-docs#tag/Brands/operation/List%20Brands)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + accuranker, + fields: { + type: "string[]", + label: "Fields", + description: "The fields to return", + optional: true, + default: [ + "id", + "last_scraped", + "group", + "domain", + "display_name", + "brand_list", + "competitors", + "history", + "created_at", + ], + }, + periodFrom: { + propDefinition: [ + accuranker, + "periodFrom", + ], + }, + periodTo: { + propDefinition: [ + accuranker, + "periodTo", + ], + }, + max: { + propDefinition: [ + accuranker, + "max", + ], + }, + }, + async run({ $ }) { + const brands = this.accuranker.paginate({ + fn: this.accuranker.listBrands, + args: { + $, + params: { + fields: this.fields.join(","), + period_from: this.periodFrom, + period_to: this.periodTo, + }, + }, + max: this.max, + }); + + const results = []; + for await (const brand of brands) { + results.push(brand); + } + + $.export("$summary", `Found ${results.length} brand(s)`); + + return results; + }, +}; diff --git a/components/accuranker/actions/list-domains/list-domains.mjs b/components/accuranker/actions/list-domains/list-domains.mjs new file mode 100644 index 0000000000000..0741767750568 --- /dev/null +++ b/components/accuranker/actions/list-domains/list-domains.mjs @@ -0,0 +1,72 @@ +import accuranker from "../../accuranker.app.mjs"; + +export default { + key: "accuranker-list-domains", + name: "List Domains", + description: "List domains in Accuranker. [See the documentation](https://app.accuranker.com/api/read-docs#tag/Domains/operation/List%20Domains)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + accuranker, + fields: { + type: "string[]", + label: "Fields", + description: "The fields to return", + optional: true, + default: [ + "id", + "display_name", + "domain", + "status", + "created_at", + "last_scraped", + ], + }, + periodFrom: { + propDefinition: [ + accuranker, + "periodFrom", + ], + }, + periodTo: { + propDefinition: [ + accuranker, + "periodTo", + ], + }, + max: { + propDefinition: [ + accuranker, + "max", + ], + }, + }, + async run({ $ }) { + const domains = this.accuranker.paginate({ + fn: this.accuranker.listDomains, + args: { + $, + params: { + fields: this.fields.join(","), + period_from: this.periodFrom, + period_to: this.periodTo, + }, + }, + max: this.max, + }); + + const results = []; + for await (const domain of domains) { + results.push(domain); + } + + $.export("$summary", `Found ${results.length} domain(s)`); + + return results; + }, +}; diff --git a/components/accuranker/actions/list-keywords/list-keywords.mjs b/components/accuranker/actions/list-keywords/list-keywords.mjs new file mode 100644 index 0000000000000..722c88ab6bda1 --- /dev/null +++ b/components/accuranker/actions/list-keywords/list-keywords.mjs @@ -0,0 +1,79 @@ +import accuranker from "../../accuranker.app.mjs"; + +export default { + key: "accuranker-list-keywords", + name: "List Keywords", + description: "List keywords for a domain in Accuranker. [See the documentation](https://app.accuranker.com/api/read-docs#tag/Keywords/operation/List%20Keywords)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + accuranker, + domainId: { + propDefinition: [ + accuranker, + "domainId", + ], + }, + fields: { + type: "string[]", + label: "Fields", + description: "The fields to return", + optional: true, + default: [ + "id", + "keyword", + "description", + "ranks", + "competitor_ranks", + ], + }, + periodFrom: { + propDefinition: [ + accuranker, + "periodFrom", + ], + }, + periodTo: { + propDefinition: [ + accuranker, + "periodTo", + ], + }, + max: { + propDefinition: [ + accuranker, + "max", + ], + max: 100, + }, + }, + async run({ $ }) { + const keywords = this.accuranker.paginate({ + fn: this.accuranker.listKeywords, + args: { + $, + domainId: this.domainId, + params: { + fields: this.fields.join(","), + period_from: this.periodFrom, + period_to: this.periodTo, + }, + }, + max: this.max, + }); + + const results = []; + for await (const keyword of keywords) { + results.push(keyword); + } + + $.export("$summary", `Found ${results.length} keyword(s)`); + + return results; + }, +}; diff --git a/components/accuranker/package.json b/components/accuranker/package.json index 7f53f61fc491c..90be230b08c15 100644 --- a/components/accuranker/package.json +++ b/components/accuranker/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/accuranker", - "version": "0.6.0", + "version": "0.7.0", "description": "Pipedream accuranker Components", "main": "accuranker.app.mjs", "keywords": [ @@ -13,6 +13,6 @@ "access": "public" }, "dependencies": { - "@pipedream/platform": "^3.0.0" + "@pipedream/platform": "^3.1.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2af094a37cb1e..2b3e597849e28 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -238,8 +238,8 @@ importers: components/accuranker: dependencies: '@pipedream/platform': - specifier: ^3.0.0 - version: 3.0.3 + specifier: ^3.1.0 + version: 3.1.0 components/accuweather: dependencies: @@ -1924,8 +1924,7 @@ importers: components/braintree: {} - components/brandblast: - specifiers: {} + components/brandblast: {} components/brandfetch: {} @@ -31287,22 +31286,22 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net superagent@7.1.6: resolution: {integrity: sha512-gZkVCQR1gy/oUXr+kxJMLDjla434KmSOKbx5iGD30Ql+AkJQ/YlPKECJy2nhqOsHLjGHzoDTXNSjhnvWhzKk7g==} engines: {node: '>=6.4.0 <13 || >=14'} - deprecated: Please upgrade to v9.0.0+ as we have fixed a public vulnerability with formidable dependency. Note that v9.0.0+ requires Node.js v14.18.0+. See https://github.com/ladjs/superagent/pull/1800 for insight. This project is supported and maintained by the team at Forward Email @ https://forwardemail.net + deprecated: Please upgrade to superagent v10.2.2+, see release notes at https://github.com/forwardemail/superagent/releases/tag/v10.2.2 - maintenance is supported by Forward Email @ https://forwardemail.net supports-color@10.0.0: resolution: {integrity: sha512-HRVVSbCCMbj7/kdWF9Q+bbckjBHLtHMEoJWlkmYzzdwhYMkjkOwubLM6t7NbWKjgKamGDrWL1++KrjUO1t9oAQ==}