diff --git a/components/barcode_lookup/actions/batch-barcode-lookup/batch-barcode-lookup.mjs b/components/barcode_lookup/actions/batch-barcode-lookup/batch-barcode-lookup.mjs new file mode 100644 index 0000000000000..805b67cced699 --- /dev/null +++ b/components/barcode_lookup/actions/batch-barcode-lookup/batch-barcode-lookup.mjs @@ -0,0 +1,33 @@ +import app from "../../barcode_lookup.app.mjs"; +import { parseObject } from "../../common/utils.mjs"; + +export default { + key: "barcode_lookup-batch-barcode-lookup", + name: "Batch Barcode Lookup", + description: "Get multiple products by barcode. [See the documentation](https://www.barcodelookup.com/api-documentation)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + app, + barcodes: { + type: "string[]", + label: "Barcodes", + description: "The barcodes to search for. You can also use a partial barcode followed by an asterisk (*).", + }, + }, + async run({ $ }) { + const response = await this.app.searchProducts({ + $, + params: { + barcode: parseObject(this.barcodes)?.join(","), + }, + }); + $.export("$summary", "Successfully retrieved products by barcodes"); + return response; + }, +}; diff --git a/components/barcode_lookup/actions/get-product-by-barcode/get-product-by-barcode.mjs b/components/barcode_lookup/actions/get-product-by-barcode/get-product-by-barcode.mjs new file mode 100644 index 0000000000000..111c87875faae --- /dev/null +++ b/components/barcode_lookup/actions/get-product-by-barcode/get-product-by-barcode.mjs @@ -0,0 +1,32 @@ +import app from "../../barcode_lookup.app.mjs"; + +export default { + key: "barcode_lookup-get-product-by-barcode", + name: "Get Product by Barcode", + description: "Get a product by barcode. [See the documentation](https://www.barcodelookup.com/api-documentation)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + app, + barcode: { + type: "string", + label: "Barcode", + description: "The barcode to search for. You can also use a partial barcode (6 digits minimum) followed by an asterisk (*).", + }, + }, + async run({ $ }) { + const response = await this.app.searchProducts({ + $, + params: { + barcode: this.barcode, + }, + }); + $.export("$summary", "Successfully retrieved product by barcode"); + return response; + }, +}; diff --git a/components/barcode_lookup/actions/search-products-by-parameters/search-products-by-parameters.mjs b/components/barcode_lookup/actions/search-products-by-parameters/search-products-by-parameters.mjs new file mode 100644 index 0000000000000..3f44af0dca496 --- /dev/null +++ b/components/barcode_lookup/actions/search-products-by-parameters/search-products-by-parameters.mjs @@ -0,0 +1,109 @@ +import app from "../../barcode_lookup.app.mjs"; + +export default { + key: "barcode_lookup-search-products-by-parameters", + name: "Search Products by Parameters", + description: "Search for products by parameters. [See the documentation](https://www.barcodelookup.com/api-documentation)", + version: "0.0.1", + type: "action", + annotations: { + destructiveHint: false, + openWorldHint: true, + readOnlyHint: true, + }, + props: { + app, + mpn: { + type: "string", + label: "MPN", + description: "MPN parameter is the manufacturer part number. `E.g. **LXCF9407**`", + optional: true, + }, + asin: { + type: "string", + label: "ASIN", + description: "ASIN parameter is the Amazon Standard Identification Number. `E.g. **B079L4WR4T**`", + optional: true, + }, + title: { + type: "string", + label: "Title", + description: "Search by product name (title) for any item. `E.g. **Red Running Shoes**`", + optional: true, + }, + category: { + type: "string", + label: "Category", + description: "Search by category - based on [Google's product taxonomy](https://www.google.com/basepages/producttype/taxonomy.en-US.txt). `E.g. **Home & Garden > Decor**`", + optional: true, + }, + manufacturer: { + type: "string", + label: "Manufacturer", + description: "search by manufacturer - use double quotes (\"\") around value for an exact match. `E.g. **\"Samsung\"**`", + optional: true, + }, + brand: { + type: "string", + label: "Brand", + description: "Search by brand - use double quotes (\"\") around value for an exact match. `E.g. **\"Calvin Klein\"**`", + optional: true, + }, + search: { + type: "string", + label: "Search", + description: "Query all the search fields including title, category, brand and MPN. `E.g. **\"Air Jordan Red Shoes Size 40\"**`", + optional: true, + }, + geo: { + type: "string", + label: "Geo", + description: "Filter online store results by geographical location", + options: [ + "us", + "gb", + "ca", + "eu", + ], + optional: true, + }, + maxResults: { + type: "integer", + label: "Max Results", + description: "The maximum number of results to return", + optional: true, + }, + }, + async run({ $ }) { + try { + const response = await this.app.paginate({ + $, + fn: this.app.searchProducts, + maxResults: this.maxResults, + params: { + mpn: this.mpn, + asin: this.asin, + title: this.title, + category: this.category, + manufacturer: this.manufacturer, + brand: this.brand, + search: this.search, + metadata: "y", + geo: this.geo, + formatted: "y", + }, + }); + + const responseArray = []; + for await (const item of response) { + responseArray.push(item); + } + + $.export("$summary", `Successfully retrieved ${responseArray.length} products`); + return responseArray; + } catch (error) { + $.export("$summary", "Successfully retrieved 0 products"); + return []; + } + }, +}; diff --git a/components/barcode_lookup/barcode_lookup.app.mjs b/components/barcode_lookup/barcode_lookup.app.mjs index 00bf75d5e208d..24d686ad8386e 100644 --- a/components/barcode_lookup/barcode_lookup.app.mjs +++ b/components/barcode_lookup/barcode_lookup.app.mjs @@ -1,11 +1,58 @@ +import { axios } from "@pipedream/platform"; + export default { type: "app", app: "barcode_lookup", propDefinitions: {}, methods: { - // this.$auth contains connected account data - authKeys() { - console.log(Object.keys(this.$auth)); + _baseUrl() { + return "https://api.barcodelookup.com/v3"; + }, + _params(params = {}) { + return { + ...params, + key: `${this.$auth.api_key}`, + }; + }, + _makeRequest({ + $ = this, params, path, ...opts + }) { + return axios($, { + url: this._baseUrl() + path, + params: this._params(params), + ...opts, + }); + }, + searchProducts(opts = {}) { + return this._makeRequest({ + path: "/products", + ...opts, + }); + }, + async *paginate({ + fn, params = {}, maxResults = null, ...opts + }) { + let hasMore = false; + let count = 0; + let page = 0; + + do { + params.page = ++page; + const { products: data } = await fn({ + params, + ...opts, + }); + for (const d of data) { + yield d; + + if (maxResults && ++count === maxResults) { + return count; + } + } + + hasMore = data?.length; + + } while (hasMore); }, }, }; diff --git a/components/barcode_lookup/common/utils.mjs b/components/barcode_lookup/common/utils.mjs new file mode 100644 index 0000000000000..dcc9cc61f6f41 --- /dev/null +++ b/components/barcode_lookup/common/utils.mjs @@ -0,0 +1,24 @@ +export const parseObject = (obj) => { + if (!obj) return undefined; + + if (Array.isArray(obj)) { + return obj.map((item) => { + if (typeof item === "string") { + try { + return JSON.parse(item); + } catch (e) { + return item; + } + } + return item; + }); + } + if (typeof obj === "string") { + try { + return JSON.parse(obj); + } catch (e) { + return obj; + } + } + return obj; +}; diff --git a/components/barcode_lookup/package.json b/components/barcode_lookup/package.json index 1029a92512a3a..7679b14de04b4 100644 --- a/components/barcode_lookup/package.json +++ b/components/barcode_lookup/package.json @@ -1,6 +1,6 @@ { "name": "@pipedream/barcode_lookup", - "version": "0.0.1", + "version": "0.1.0", "description": "Pipedream Barcode Lookup Components", "main": "barcode_lookup.app.mjs", "keywords": [ @@ -11,5 +11,8 @@ "author": "Pipedream (https://pipedream.com/)", "publishConfig": { "access": "public" + }, + "dependencies": { + "@pipedream/platform": "^3.1.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c733edd6811f7..58be75c508944 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1444,7 +1444,11 @@ importers: specifier: ^0.10.0 version: 0.10.0 - components/barcode_lookup: {} + components/barcode_lookup: + dependencies: + '@pipedream/platform': + specifier: ^3.1.0 + version: 3.1.0 components/baremetrics: dependencies: @@ -13828,8 +13832,7 @@ importers: components/stack_overflow_for_teams: {} - components/stackby: - specifiers: {} + components/stackby: {} components/stackshare_api: {} @@ -31376,22 +31379,22 @@ packages: superagent@3.8.1: resolution: {integrity: sha512-VMBFLYgFuRdfeNQSMLbxGSLfmXL/xc+OO+BZp41Za/NRDBet/BNbkRJrYzCUu0u4GU0i/ml2dtT8b9qgkw9z6Q==} engines: {node: '>= 4.0'} - 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 + 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 superagent@4.1.0: resolution: {integrity: sha512-FT3QLMasz0YyCd4uIi5HNe+3t/onxMyEho7C3PSqmti3Twgy2rXT4fmkTz6wRL6bTF4uzPcfkUCa8u4JWHw8Ag==} engines: {node: '>= 6.0'} - 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 + 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 superagent@5.3.1: resolution: {integrity: sha512-wjJ/MoTid2/RuGCOFtlacyGNxN9QLMgcpYLDQlWFIhhdJ93kNscFonGvrpAHSCVjRVj++DGCglocF7Aej1KHvQ==} engines: {node: '>= 7.0.0'} - 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 + 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 superagent@7.1.6: resolution: {integrity: sha512-gZkVCQR1gy/oUXr+kxJMLDjla434KmSOKbx5iGD30Ql+AkJQ/YlPKECJy2nhqOsHLjGHzoDTXNSjhnvWhzKk7g==} engines: {node: '>=6.4.0 <13 || >=14'} - 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 + 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 supports-color@10.0.0: resolution: {integrity: sha512-HRVVSbCCMbj7/kdWF9Q+bbckjBHLtHMEoJWlkmYzzdwhYMkjkOwubLM6t7NbWKjgKamGDrWL1++KrjUO1t9oAQ==}